Bug #65583 [NEW]: PDO MySQL driver does not escape properly backslashes
From: kevin at les-tilleuls dot coop
Operating system: Mac OS X
PHP version: 5.5.3
Package: PDO related
Bug Type: Bug
Bug description:PDO MySQL driver does not escape properly backslashes
Description:
------------
PDO MySQL driver does not escape backslashes in string.
The MySQL doc indicates that backslashes must be doubled to be escaped
http://dev.mysql.com/doc/refman/5.6/en/string-literals.html
The driver does not do that. See the script above.
Should this escaping be done by PDO or a higher layer like Doctrine DBAL?
Test script:
---------------
<?php
define('DSN', 'mysql:dbname=testdb;host=127.0.0.1');
define('USER', 'root');
define('PASSWORD', '');
/* DATABASE STRUCTURE
CREATE TABLE test (
test varchar(255) NOT NULL,
PRIMARY KEY (test)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
*/
$dbh = new PDO(DSN, USER, PASSWORD);
$data = '\\' . uniqid();
$stmt = $dbh->prepare('INSERT INTO test(test) VALUES(:data)');
$stmt->execute(array('data' => $data));
$stmt = $dbh->prepare('SELECT test FROM test WHERE test LIKE :data');
$stmt->execute(array('data' => $data));
var_dump($stmt->fetchColumn());
$stmt = $dbh->prepare('SELECT test FROM test WHERE test LIKE :data');
$stmt->execute(array('data' => str_replace('\\', '\\\\',
$data)));
var_dump($stmt->fetchColumn());
Expected result:
----------------
string(14) "\521f3f450f597"
bool(false)
Actual result:
--------------
bool(false)
string(14) "\521f3f450f597"
--
Edit bug report at https://bugs.php.net/bug.php?id=65583&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=65583&r=trysnapshot54
Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=65583&r=trysnapshot53
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=65583&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=65583&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=65583&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=65583&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=65583&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=65583&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=65583&r=support
Expected behavior: https://bugs.php.net/fix.php?id=65583&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=65583&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=65583&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=65583&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65583&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=65583&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=65583&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=65583&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=65583&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=65583&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=65583&r=mysqlcfg
Thread (3 messages)
- kevin at les-tilleuls dot coop