Limit in PDO

I am having problem in using the Limit in PDO,I get sql syntax error.

  $cmd = $this->connection->prepare('SELECT * from user
                                           Limit ?,?

                                           ');
        $cmd->execute(array($start,$endlimit));

What is your error?

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

Just google that error. Check this out

http://stackoverflow.com/questions/4544051/sqlstate42000-syntax-error-or-access-violation-1064-you-have-an-error-in-you

Looks like it might be a String vs. Int thing. does this still error?
$cmd->execute(array((int)$start,(int)$endlimit));

Are the variables coming from dirty user supplied values?

Unless told otherwise, PDO sends all params in as strings. You need to bind the params as integers. You can’t do this with execute, you’ll need to use the bindParam method of the statement object.

1 Like

Okay solved it, using bindValue, bindParam doesn’t work.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.