note 100487 rejected from pdostatement.bindparam by danbrown

From: Date: Tue, 19 Oct 2010 14:04:00 +0000
Subject: note 100487 rejected from pdostatement.bindparam by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-173279@lists.php.net to get a copy of this message
Note Submitter: jamone_95134 at yahoo dot com ---- Hi I would like help in knowing how to use the IN clause in a sql query, and be able to bind a parameter to such a query. Below is an example, and the error I get: $objPDO = new PDO("mysql:host=$hostName; dbname=$dbName", $userName, $passWord); $id = "(1, 2, 7)"; $objPDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $strQuery = "SELECT * FROM book WHERE id IN :id"; $objStatement = $objPDO->prepare($strQuery); $objStatement->bindParam(":id", $id, PDO::PARAM_STR); $objStatement->execute(); An error occurred while executing query statement: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an e rror in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''(1, 2, 7)'' at line 1

« previous php.notes (#173279) next »