note 94219 added to pdostatement.bindvalue

From: Date: Fri, 23 Oct 2009 04:16:18 +0000
Subject: note 94219 added to pdostatement.bindvalue
Groups: php.notes 
Request: Send a blank email to php-notes+get-162000@lists.php.net to get a copy of this message
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 . ';'; ---- Server IP: 69.147.83.197 Probable Submitter: 96.23.245.97 ---- Manual Page -- http://www.php.net/manual/en/pdostatement.bindvalue.php Edit -- https://master.php.net/note/edit/94219 Del: integrated -- https://master.php.net/note/delete/94219/integrated Del: useless -- https://master.php.net/note/delete/94219/useless Del: bad code -- https://master.php.net/note/delete/94219/bad+code Del: spam -- https://master.php.net/note/delete/94219/spam Del: non-english -- https://master.php.net/note/delete/94219/non-english Del: in docs -- https://master.php.net/note/delete/94219/in+docs Del: other reasons-- https://master.php.net/note/delete/94219 Reject -- https://master.php.net/note/reject/94219 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#162000) next »