note 125592 added to pdostatement.execute

From: Date: Fri, 11 Dec 2020 05:06:32 +0000
Subject: note 125592 added to pdostatement.execute
Groups: php.notes 
Request: Send a blank email to php-notes+get-215970@lists.php.net to get a copy of this message
As already pointed out by some folks, DON'T PASS ARRAYS KEYED WITH NAMES TO QUESTION MARK PARAMETERS! <?php $sth = $dbh->prepare('INSERT INTO fruit (name, colour, colories) VALUES (?, ?, ?)'); // This is wrong! // $param = array("name" => "apple", "colour" => "red", "colories" => 150); // Array must be keyed with integers starting from zero $param = array("apple", "red", 150); $sth->execute($param); ---- Server IP: 45.112.84.4 Probable Submitter: 45.112.85.244 (proxied: 180.217.146.242) ---- Manual Page -- http://php.net/manual/en/pdostatement.execute.php Edit -- https://master.php.net/note/edit/125592 Del: integrated -- https://master.php.net/note/delete/125592/integrated Del: useless -- https://master.php.net/note/delete/125592/useless Del: bad code -- https://master.php.net/note/delete/125592/bad+code Del: spam -- https://master.php.net/note/delete/125592/spam Del: non-english -- https://master.php.net/note/delete/125592/non-english Del: in docs -- https://master.php.net/note/delete/125592/in+docs Del: other reasons-- https://master.php.net/note/delete/125592 Reject -- https://master.php.net/note/reject/125592 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#215970) next »