Bug #73224 [NEW]: Bug when binding values that are compared with columns with KEY constraints
From: uzbgi at student dot kit dot edu
Operating system: Linux - Debian 3.2.73-2
PHP version: 7.0.11
Package: PDO MySQL
Bug Type: Bug
Bug description:Bug when binding values that are compared with columns with KEY constraints
Description:
------------
PDOStatement::bindValue does not work properly when the value in the
query is compared with a column that uses mysql "KEY constraints" or
mysql "FOREIGN KEY constraints".
We have the mysql query "SELECT * FROM dogs WHERE owner=:owner".
When we call e.g. $stmt->bindValue(':owner', '101.7', PDO::PARAM_INT)
the value 101.7 is rouned to 102, if ':owner' is compared with a column
that uses a KEY constraint. But this behaviour is wrong.
The same happens also when binding via PDOStatement::bindParam() or
PDOStatement::execute().
This problem does ONLY occur for columns that have mysql key
constraints.
Test script:
---------------
$host = "YOUR_HOST";
$dbname = "YOUR_DATABASE";
$user = "YOUR_USERNAME";
$pass = "YOUR_PASSWORD";
$pdo = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass );
$stmt = $pdo->prepare('SELECT * FROM dogs WHERE owner=:owner');
// 101.7 becomes however 102
$stmt->bindValue(':owner', '101.7', PDO::PARAM_INT);
$stmt->execute();
print_r( $stmt->fetch(PDO::FETCH_ASSOC) );
/**************
# MYSQL script for this test script
CREATE TABLE IF NOT EXISTS dogs (
id int(10) unsigned NOT NULL AUTO_INCREMENT,
name varchar(50) NOT NULL,
owner int(10) unsigned NOT NULL,
PRIMARY KEY (id),
KEY owner (owner) # <- This is my KEY constraint
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4;
INSERT INTO dogs (id, name, owner) VALUES (1,
'Rex', 101), (2,
'Roxy', 102);
**************/
Expected result:
----------------
Array ()
Actual result:
--------------
Array ( [id] => 2 [name] => Roxy [owner] => 102 )
--
Edit bug report at https://bugs.php.net/bug.php?id=73224&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=73224&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=73224&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=73224&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=73224&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=73224&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=73224&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=73224&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=73224&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=73224&r=support
Expected behavior: https://bugs.php.net/fix.php?id=73224&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=73224&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=73224&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=73224&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73224&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=73224&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=73224&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=73224&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=73224&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=73224&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=73224&r=mysqlcfg
Thread (5 messages)
- uzbgi at student dot kit dot edu