go to bug id or search bugs for
When using PDO_DBLIB to prepare statements, numerics are quoted and fatal error is returned.
OS : Centos 7.2
PHP : 7.2.2
Freetds : 0.95.81
DBMS : Sybase ASE 12.5.4 & Sybase ASE 16.0
// create table foo ( n numeric(14,2) null )
$db = new \PDO("dblib:host=$hostname:$port;dbname=$dbname", "$username", "$pw");
$n = 123.45;
$query = 'INSERT INTO foo ( n ) values ( :n )';
$stmt = $db->prepare($query);
$stmt->bindParam(':n', $n, \PDO::PARAM_STR);
SQLSTATE[HY000]: General error: 20018 Implicit conversion from datatype 'VARCHAR' to 'NUMERIC' is not allowed. Use the CONVERT function to run this query.
 (severity 16) [INSERT INTO foo ( n ) values ( '123.45' )]
Add a Patch
Add a Pull Request
Am I missing something here?
You are telling PDO the param must be treated as a string using `\PDO::PARAM_STR` so indeed it is treated as a string.
PDO::PARAM_BOOL Represents a boolean data type.
PDO::PARAM_NULL Represents the SQL NULL data type.
PDO::PARAM_INT Represents the SQL INTEGER data type.
PDO::PARAM_STR Represents the SQL CHAR, VARCHAR, or other string data type.
According to https://wiki.php.net/rfc/pdo_float_type (see Introduction) ;
> The PDO extension does not have a type to represent floating point values.
> The current recommended practice is to use PDO::PARAM_STR.
I haven't seen that particular error. Wondering if it's an environmental thing. The pdo_dblib driver is unfortunately limited with how it can handle types. It doesn't support true prepared statements, so the only flexibility would be around what kind of SQL string you can get it to produce. There isn't one that handles decimal values. I had worked on an RFC to deal with this:
I had trouble getting traction. Perhaps you have a suggestion on how to revive it?
All that said, I'd suggest working a CONVERT call into your query as a workaround.