Doc #63139 [Com]: PDO repeated use of prepared statement

From: Date: Mon, 01 Oct 2012 20:12:06 +0000
Subject: Doc #63139 [Com]: PDO repeated use of prepared statement
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-8915@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=63139&edit=1 ID: 63139 Comment by: JackDHunter26 at yahoo dot com Reported by: davogotland at gmail dot com Summary: PDO repeated use of prepared statement Status: Open Type: Documentation Problem Package: Website problem PHP Version: Irrelevant Block user comment: N Private report: N New Comment: Try useing :Name1 and :Value1. Likely it has problems seeing the difference between field names and varibles. Previous Comments: ------------------------------------------------------------------------ [2012-09-22 13:50:11] davogotland at gmail dot com Description: ------------ Hello! I'm using PHP 5.2.5, so perhaps this is about my PHP version being old. But as I've noticed, changing whether or not a parameter needs to be sent by reference doesn't often happen. The problem I've found is on this page: http://php.net/manual/en/pdo.prepared-statements.php Under Example #1 Repeated inserts using prepared statements There is some code that I have to modify to get to work. <?php $stmt = $dbh->prepare("INSERT INTO REGISTRY (name, value) VALUES (:name, :value)"); $stmt->bindParam(':name', $name); // THIS $stmt->bindParam(':value', $value); // AND THIS //does not work for me. i have to do $stmt->bindParam(':name', &$name); // PLEASE NOTE $stmt->bindParam(':value', &$value); // THE AMPERSANDS // insert one row $name = 'one'; $value = 1; $stmt->execute(); // insert another row with different values $name = 'two'; $value = 2; $stmt->execute(); ?> I also found this (from 2010) on the page http://php.net/manual/en/pdostatement.bindparam.php#98145 This works ($val by reference): <?php foreach ($params as $key => &$val) { $sth->bindParam($key, $val); } ?> This will fail ($val by value, because bindParam needs &$variable): <?php foreach ($params as $key => $val) { $sth->bindParam($key, $val); } ?> At the top of this last page, the version is declared as PHP 5 >= 5.1.0, which would include 5.2, 5.3 and so on. This is why I think this is a bug in the documentation. Regards, -David ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=63139&edit=1

« previous php.doc.bugs (#8915) next »