php - PDO Mysql Syntax error 1064 -


i run following code:

$conn = new pdo(....); .... pdo attributes ...  $limitvalue = 0; $limit = 10; $sql = $conn->prepare("select * table1 limit ?, ?"); $sql->bindparam(1, $limitvalue, pdo::param_int); $sql->bindparam(2, $limit, pdo::param_int); $sql->execute(); 

and get:

uncaught exception 'pdoexception' message 'sqlstate[42000]: syntax error or access violation: 1064 have error in sql syntax; check manual corresponds mysql server version right syntax use near 'null, 10' @ line 1'

it happens particular query. else ok.

btw: know may stupid prepared statements "in-code" values. example. in fact values depending on page number doesn't matter here - query giving same error too.


if interested, php version is: 5.3.4rc2 , mysql's is: mysqlnd 5.0.7-dev - 091210 - $revision: 304625 $

this seems php bug : pdo ignores param_int constant , use $limit , $limitvalue variables string. quoted in query when bound.

try using :

$sql->bindparam(1, (int)$limitvalue, pdo::param_int); $sql->bindparam(2, (int)$limit, pdo::param_int); 

to force variables type int.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -