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

From: Date: Sat, 22 Sep 2012 13:50:11 +0000
Subject: Doc #63139 [NEW]: PDO repeated use of prepared statement
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-8887@lists.php.net to get a copy of this message
From: davogotland at gmail dot com Operating system: PHP version: Irrelevant Package: Website problem Bug Type: Documentation Problem Bug description:PDO repeated use of prepared statement 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 bug report at https://bugs.php.net/bug.php?id=63139&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=63139&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=63139&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=63139&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=63139&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=63139&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=63139&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=63139&r=needscript Try newer version: https://bugs.php.net/fix.php?id=63139&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=63139&r=support Expected behavior: https://bugs.php.net/fix.php?id=63139&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=63139&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=63139&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=63139&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=63139&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=63139&r=dst IIS Stability: https://bugs.php.net/fix.php?id=63139&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=63139&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=63139&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=63139&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=63139&r=mysqlcfg

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