note 111468 deleted from pdostatement.bindparam by danbrown

From: Date: Mon, 04 Mar 2013 17:55:51 +0000
Subject: note 111468 deleted from pdostatement.bindparam by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-193854@lists.php.net to get a copy of this message
Note Submitter: lars at larseighner dot com ---- with the MySQL driver, backticking as in the examples fails for me throwing the yada-yada 1-based exception. (/:pagename: not found PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: Columns/Parameters are 1-based' in /usr/local/data/home/lars/lib/update_pagenames.php:44 Stack trace: #0 /usr/local/data/home/lars/lib/update_pagenames.php(44): PDOStatement->bindParam(0, '.flock') #1 {main} thrown in /usr/local/data/home/lars/lib/update_pagenames.php on line 44 ) Fails with prepared SELECT, INSERT, and DELETE statements: $sth2->bindParam(:pagename,$result['pagename']); But plain single quotes work. Works with above types of prepared statements: $sth2->bindParam(':pagename',$result['pagename']); Working examples: $sth1 = $dbh->prepare("INSERT INTO xwikipages(pagename)VALUES(:pagename)"); $sth1->bindParam(':pagename',$name); and $sth = $dbh->prepare("SELECT * FROM xwikipages WHERE pagename=:pagename"); foreach($names as $name){ $sth->bindParam(':pagename',$name,PDO::PARAM_STR); try{ $sth->execute(); }catch (PDOException $ex) { echo $ex->getMessage(),'Cannot select',"\n"; } $res = $sth->fetchAll(); and $sth2=$dbh->prepare("DELETE FROM xwikipages WHERE pagename=(:pagename)"); foreach($res as $result){ if( ! array_key_exists($result['pagename'],$keynames) ){ echo $result['pagename'],' exists in db but not in list.'; $sth2->bindParam(':pagename',$result['pagename']); try{ $count = $sth2->execute();} catch (PDOException $ex) { echo $ex->getMessage(),'Cannot delete',"\n"; } etc.

« previous php.notes (#193854) next »