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
Post a Comment