Skip to main content

PHP PDO LIMIT


Had an issue with PDO and MySQL SELECT statement while using LIMIT in it.
It threw an exception while I tried to bind the parameter like I normally do.


$pdo = $db->prepare("SELECT * FROM table LIMIT :limit");
$pdo->bindValue('limit', $limit, PDO::PARAM_INT)
$pdo->execute();

From here I found a solution. It is necessary to cast the parameter $limit. Like this..

$pdo->bindValue('limit', (int) $limit, PDO::PARAM_INT)

Comments

Popular posts from this blog

brew, "pear install ...", Log for example..

I had issues while installing Log package from Pear. I used brew to get PHP (5.5.17) running on my MBP. So, back to the installing issue - if I tried to execute following command I got an error .. $ pear install Log No releases available for package "pear.php.net/Log" intallation failed So, failed. Then I tried to download the package using "pear download Log". Failed too. Solution was to go to Log package Pear page  and manually download the package. And in terminal you should executed the same installation command and point to downloaded file.. $ pear install /path/to/downloaded/Log-1.12.8.tar .. output skipped .. install ok: channel://pear.php.net/Log-1.12.8 Done. Anyway, there are probably other (better, more modern) logging libraries out there for PHP applications. Feel free to post your favorite one with short description to comments. Thanks in advance!