note 80499 added to function.PDOStatement-execute

From: Date: Sat, 19 Jan 2008 04:33:53 +0000
Subject: note 80499 added to function.PDOStatement-execute
Groups: php.notes 
Request: Send a blank email to php-notes+get-135214@lists.php.net to get a copy of this message
When passing an array of values to execute when your query contains question marks, note that the array must be keyed numerically from zero. If it is not, run array_values() on it to force the array to be re-keyed. <?php $anarray = array(42 => "foo", 101 => "bar"); $statement = $dbo->prepare("SELECT * FROM table WHERE col1 = ? AND col2 = ?"); //This will not work $statement->execute($anarray); //Do this to make it work $statement->execute(array_values($anarray)); ?> ---- Server IP: 209.41.74.194 Probable Submitter: 76.227.11.220 ---- Manual Page -- http://www.php.net/manual/en/function.PDOStatement-execute.php Edit -- https://master.php.net/note/edit/80499 Del: integrated -- https://master.php.net/note/delete/80499/integrated Del: useless -- https://master.php.net/note/delete/80499/useless Del: bad code -- https://master.php.net/note/delete/80499/bad+code Del: spam -- https://master.php.net/note/delete/80499/spam Del: non-english -- https://master.php.net/note/delete/80499/non-english Del: in docs -- https://master.php.net/note/delete/80499/in+docs Del: other reasons-- https://master.php.net/note/delete/80499 Reject -- https://master.php.net/note/reject/80499 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#135214) next »