note 111468 added to pdostatement.bindparam

From: Date: Fri, 22 Feb 2013 10:24:26 +0000
Subject: note 111468 added to pdostatement.bindparam
Groups: php.notes 
Request: Send a blank email to php-notes+get-193725@lists.php.net to get a copy of this message
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. ---- Server IP: 69.147.83.199 Probable Submitter: 71.20.75.102 ---- Manual Page -- http://php.net/manual/en/pdostatement.bindparam.php Edit -- https://master.php.net/note/edit/111468 Del: integrated -- https://master.php.net/note/delete/111468/integrated Del: useless -- https://master.php.net/note/delete/111468/useless Del: bad code -- https://master.php.net/note/delete/111468/bad+code Del: spam -- https://master.php.net/note/delete/111468/spam Del: non-english -- https://master.php.net/note/delete/111468/non-english Del: in docs -- https://master.php.net/note/delete/111468/in+docs Del: other reasons-- https://master.php.net/note/delete/111468 Reject -- https://master.php.net/note/reject/111468 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#193725) next »