From: phpbugs at filofox dot com
Operating system: Linux Debian Sarge 3.1
PHP version: 5.2.1
PHP Bug Type: PDO related
Bug description: PDO::execute() errors when parameters are used in LIMIT clause
Description:
------------
The following emerged after upgrading from 5.2.0 to 5.2.1 and has been
checked in both versions: the error only occurs in 5.2.1 .
When passing parameters into a LIMIT clause using PDO::execute(), it
appears that PDO is quoting the parameters, which causes MYSQL to throw an
error.
FYI: PDO_MYSQL is built against MySQL client library 5.0.18.
Reproduce code:
---------------
$dbh = new PDO('mysql:localhost;dbname=my_db', 'user', '' );
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
try{
$query = $dbh->prepare( 'SELECT * FROM some_table LIMIT :start, :limit'
);
if ( $query->execute ( array ( 'start' => 0, 'limit' => 10 ) ) )
{
while ( $row = $query->fetch ( PDO::FETCH_ASSOC ) )
{
print_r($row);
}
$query->closeCursor();
}
} catch( Exception $e ){
print_r( $e );
}
Expected result:
----------------
A number of rows are returned.
Actual result:
--------------
An exception is thrown:
PDOException Object
(
[message:protected] => SQLSTATE[42000]: Syntax error or access
violation: 1064 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 ''0', '10'' at line 1
[string:private] =>
[code:protected] => 42000
[file:protected] => [my_file].php
[line:protected] => 19
[trace:private] => Array
(
[0] => Array
(
[file] => [my_file].php
[line] => 19
[function] => execute
[class] => PDOStatement
[type] => ->
[args] => Array
(
[0] => Array
(
[start] => 0
[limit] => 10
)
)
)
)
[errorInfo] => Array
(
[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 ''0', '10'' at line 1
)
)
--
Edit bug report at http://bugs.php.net/?id=40740&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=40740&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=40740&r=trysnapshot52
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=40740&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=40740&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=40740&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=40740&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=40740&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=40740&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=40740&r=support
Expected behavior: http://bugs.php.net/fix.php?id=40740&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=40740&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=40740&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=40740&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=40740&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=40740&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=40740&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=40740&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=40740&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=40740&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=40740&r=mysqlcfg