|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2018-02-08 18:21 UTC] equaproduction at gmail dot com
Description:
------------
When using PDO_DBLIB to prepare statements, numerics are quoted and fatal error is returned.
PDOStatement::bindValue()
PDOStatement::bindParam()
OS : Centos 7.2
PHP : 7.2.2
Freetds : 0.95.81
DBMS : Sybase ASE 12.5.4 & Sybase ASE 16.0
Test script:
---------------
// create table foo ( n numeric(14,2) null )
$db = new \PDO("dblib:host=$hostname:$port;dbname=$dbname", "$username", "$pw");
$db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$n = 123.45;
$query = 'INSERT INTO foo ( n ) values ( :n )';
$stmt = $db->prepare($query);
$stmt->bindParam(':n', $n, \PDO::PARAM_STR);
$stmt->execute();
Actual result:
--------------
SQLSTATE[HY000]: General error: 20018 Implicit conversion from datatype 'VARCHAR' to 'NUMERIC' is not allowed. Use the CONVERT function to run this query.
[20018] (severity 16) [INSERT INTO foo ( n ) values ( '123.45' )]
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 20:00:01 2025 UTC |
We witnessed the same problem since upgrading to PHP 7.2. Database: Sybase ASE 15.7 Previously on PHP 7.0.33 we succeeded in binding decimal values with PDO::PARAM_INT $query = 'SELECT 1 WHERE 12.345 = :1'; $stmt = $db->prepare($query); $stmt->bindParam(':1', 12.345, PDO::PARAM_INT); $stmt->execute(); -> fetches 1 in PHP 7.0 - Ok After Upgrading to PHP 7.2.24 these bindings fail, since the values get rounded to integers. $query = 'SELECT 1 WHERE 12.345 = :1'; $stmt = $db->prepare($query); $stmt->bindParam(':1', 12.345, PDO::PARAM_INT); $stmt->execute(); -> fetches no rows in PHP 7.2 According to some comments, we tried binding decimal values with PDO::PARAM_STR, which results in this error. $query = 'SELECT 1 WHERE 12.345 = :1'; $stmt = $db->prepare($query); $stmt->bindParam(':1', 12.345, PDO::PARAM_STR); $stmt->execute(); -> SQLSTATE[HY000]: General error: 20018 Implicit conversion from datatype 'VARCHAR' to 'NUMERIC' is not allowed. Use the CONVERT function to run this query. [20018] (severity 16) [select 1 where 12.345 = '12.345'] Surprisingly the last try (PARAM_STR) works perfectly for Microsoft-SQL Databases! Sybase Database with PHP >= 7.2 seems to be affected only.