Doc #63139 [Opn->Nab]: PDO repeated use of prepared statement

From: Date: Sat, 12 Jan 2013 05:20:02 +0000
Subject: Doc #63139 [Opn->Nab]: PDO repeated use of prepared statement
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-9394@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 Updated by: frozenfire@php.net Reported by: davogotland at gmail dot com Summary: PDO repeated use of prepared statement -Status: Open +Status: Not a bug Type: Documentation Problem Package: Website problem PHP Version: Irrelevant Block user comment: N Private report: N New Comment: This is not a bug. It's hard to nail down exactly what issue you might be incurring, but my suspicion is that your issue is due to the way you are getting each value from the array. If you do not use the $key => &$value syntax, then it produces a copy of the value from the array, not a reference. Call-time pass-by-reference is deprecated in PHP 5.3 and removed in PHP 5.4, so that's definitely not something to be added to the documentation. Previous Comments: ------------------------------------------------------------------------ [2012-10-01 20:12:06] JackDHunter26 at yahoo dot com Try useing :Name1 and :Value1. Likely it has problems seeing the difference between field names and varibles. ------------------------------------------------------------------------ [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 (#9394) next »