From: dan dot franklin at pearson dot com
Operating system: RHEL 5.3
PHP version: 5.2.9
PHP Bug Type: PDO related
Bug description: PDO-mysql cannot bind LIMIT or OFFSET
Description:
------------
In moving from PHP 5.1.6 to 5.2.9 I've lost the ability to bind to a LIMIT
or OFFSET parameter against MySQL 5.0; that is, if I have
... LIMIT ?
or
... OFFSET ?
it fails with
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 ''3'' at line 1
(where "3" is the actual value of the parameter bound to the ?).
Reproduce code:
---------------
<?php
$dsn = "mysql:host=localhost;dbname=test";
$dbh = new PDO($dsn, '', '', array());
run_PDO($dbh, "CREATE TABLE t (n int)", array());
run_PDO($dbh, "select n FROM t LIMIT ?", array(3));
run_PDO($dbh, "select n FROM t LIMIT 3 OFFSET ?", array(3));
run_PDO($dbh, "DROP TABLE t", array());
function run_PDO($dbh, $sql, $params) {
$stmt = $dbh->prepare($sql);
if (!$stmt) {
$i = $dbh->errorInfo();
print "Preparing \"$sql\" failed: $i[2]\n";
} else if (!$stmt->execute($params)) {
$i = $stmt->errorInfo();
print "Executing \"$sql\" failed: $i[2]\n";
} else {
print "\"$sql\" succeeded\n";
}
}
?>
Expected result:
----------------
"CREATE TABLE t (n int)" succeeded
"select n FROM t LIMIT ?" succeeded
"select n FROM t LIMIT 3 OFFSET ?" succeeded
"DROP TABLE t" succeeded
(This is what happens with PHP 5.1.6 MySql 5.0.45)
Actual result:
--------------
"CREATE TABLE t (n int)" succeeded
Executing "select n FROM t LIMIT ?" failed: 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 ''3'' at line 1
Executing "select n FROM t LIMIT 3 OFFSET ?" failed: 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 ''3'' at line 1
"DROP TABLE t" succeeded
(With PHP 5.2.9 MySQL 5.0.77)
--
Edit bug report at http://bugs.php.net/?id=47960&edit=1
--
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=47960&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=47960&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=47960&r=trysnapshot60
Fixed in CVS:
http://bugs.php.net/fix.php?id=47960&r=fixedcvs
Fixed in CVS and need be documented:
http://bugs.php.net/fix.php?id=47960&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=47960&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=47960&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=47960&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=47960&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=47960&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=47960&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=47960&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=47960&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=47960&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=47960&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=47960&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=47960&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=47960&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=47960&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=47960&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=47960&r=mysqlcfg