From:
Operating system: linux (centos 5.5)
PHP version: 5.2.17
Package: PDO related
Bug Type: Bug
Bug description:Parse error with single quote in sql comment (pdo-mysql)
Description:
------------
Using php 5.2.17
Tested PDO with mysql, haven't tried other drivers.
Configure Command => './configure' '--disable-cgi' '--with-mysql'
'--enable-pdo' '--with-pdo-mysql' '--with-libdir=lib64'
There is a PDO parsing error when a single quote is inside a block comment.
This seems to only occur when there is an input parameter between a
commented single quote and any other single quote, either as part of the
query or in another comment.
It looks like the single quotes aren't getting ignored in the comment, and
cause parameters to not be replaced with their values.
Example SQL that causes a parse error:
/* ' */ select ? as f1, 'foo' as f2
This also causes errors:
/* ' */ select ? as f1 /* ' */
Test script:
---------------
<?
//This query breaks:
$query = "/* ' */ select ? as f1, 'bar' as f2";
//This query also breaks:
//$query = "/* ' */ select ? as f1 /* ' */";
$pdodb = new PDO("mysql:dbname=test;host=127.0.0.1", "testuser",
"testuser");
$stmt = $pdodb->prepare($query);
if (!$stmt->execute(array("foo"))) {
$errInfo = $stmt->errorInfo();
print_r($errInfo);
}
?>
Expected result:
----------------
The single quotes should be completely ignored when inside comments, and
the ? should be replaced with the input parameter value "'foo'".
Actual result:
--------------
The query doesn't execute successfully, with the following PDO error info:
[0] => 42000
[1] => 1064
[2] => You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near
'? as f1, 'bar' as f2' at line 1
--
Edit bug report at http://bugs.php.net/bug.php?id=54929&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=54929&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=54929&r=trysnapshot53
Try a snapshot (trunk):
http://bugs.php.net/fix.php?id=54929&r=trysnapshottrunk
Fixed in SVN:
http://bugs.php.net/fix.php?id=54929&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=54929&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=54929&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=54929&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=54929&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=54929&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=54929&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=54929&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=54929&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=54929&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=54929&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=54929&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=54929&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=54929&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=54929&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=54929&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=54929&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=54929&r=mysqlcfg