note 94219 deleted from pdostatement.bindvalue by thiago

From: Date: Fri, 23 Oct 2009 11:10:28 +0000
Subject: note 94219 deleted from pdostatement.bindvalue by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-162010@lists.php.net to get a copy of this message
Note Submitter: fmaz008 at gmail dot com ---- If you want to bind an integer, you must be aware that PDO will quote the value: $query = 'SELECT * ' FROM aa WHERE id=? LIMIT ?,?;'; $prep = $db->prepare($query); $prep->bindValue(1, (int)$this->id); //1 $prep->bindValue(2, (int)$startFrom); //1 $prep->bindValue(3, (int)$lenght); //16 $prep->execute(); will produce: SELECT * ' FROM aa WHERE id='1' LIMIT '1','16'; So the query will fail because the limit must have a "true" interger, not quoted. The workarround for this until now seems to be: $query = 'SELECT * ' FROM aa WHERE id=? LIMIT ' . (int)$startFrom . ',' . (int)$lenght . ';';

« previous php.notes (#162010) next »