Pdo Hy093 Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us
Hy093 Invalid Parameter Number
Learn more about Stack Overflow the company Business Learn more about hiring developers pdostatement::execute(): sqlstate[hy093]: invalid parameter number: parameter was not defined or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack
Array ( [0] => Hy093 [1] => [2] => )
Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Why am I getting error SQLSTATE[HY093]: Invalid sqlstate[hy093]: invalid parameter number: number of bound variables does not match number of tokens parameter number: ? How can I fix it? up vote 0 down vote favorite Based on this question How to insert array into mysql using PDO and bindParam? I'm trying to insert values of an array into mysql via PDO. I'm having a hard time of it, because I keep getting the following error. SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of pdo errorinfo tokens for this line $stmt->execute(); I'm guessing the problem has something to do with this line $stmt->bindParam(':val$count', $val,PDO::PARAM_STR); Specifically 'val$count', but I'm not sure exactly what is going wrong. QUESTION: What am I doing wrong? How can I fix this? Anyway here is the code I'm using along with the sample array. $lastInsertValue=87; $qid[0][0]=1; $qid[0][1]=1; $qid[1][0]=2; $qid[1][1]="null"; $qid[2][0]=3; $qid[2][1]=0; $array_count = count($qid); if (isset($lastInsertValue)) { try { $dbh = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password); $stqid=array(); $a=0; for ($i=0; $i<$array_count; $i++) { $stqid[$a]=$lastInsertValue; $a++; $stqid[$a]=$qid[$i][0]; $a++; $stqid[$a]=$qid[$i][1]; $a++; } $sql = "INSERT INTO qresults (instance, qid, result) VALUES ( :val0, :val1, :val2)"; $count = 0; $stmt = $dbh->prepare($sql); foreach ($stqid as $val) { $stmt->bindParam(':val$count', $val,PDO::PARAM_STR); $count++; } $stmt->execute(); $dbh = null; } catch(PDOException $e) { echo $e->getMessage(); } } mysql arrays pdo share|improve this question asked Mar 29 '12 at 5:46 oooooo 1,22752852 add a comment| 3 Answers 3 active oldest votes up vote 2 down vote accepted Yikes, so many issues. Your array building is so verbose. Try this $stqid = array(); foreach ($qid as $qidArr) { $stqid[] = $lastInsertValue; // no idea why you repeat this $stqid[] = $qidArr[0]; $stqid[] = $qidArr[1]; } Use positional placeholders if y
here for a quick overview of the site Help Center Detailed answers to any questions you might
Pdo Param_str
have Meta Discuss the workings and policies of this site About pdo execute Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting
Php Pdo
ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million http://stackoverflow.com/questions/9919715/why-am-i-getting-error-sqlstatehy093-invalid-parameter-number-how-can-i-fi programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Strange PDO error hy093 up vote 1 down vote favorite First of all, excuse me, if similar questions have been asked before. But I did not find anything that could help me with my problem. On it goes: In http://stackoverflow.com/questions/15724881/strange-pdo-error-hy093 a class, I generate an SQL statement like this: $params = array(); $query = 'INSERT INTO '.TABLE_SETTINGS.' SET type=:type,'; $params[] = array('type' => $setting['type']); if(!isset($setting['attributes'])){ $query .= 'attributes=NULL,'; } else { $query .= 'attributes=:attributes,'; $params[] = array('attributes' => $setting['attributes']); } if(!isset($setting['partid'])){ $query .= 'partid=NULL,'; } else { $query .= 'partid=:partid,'; $params[] = array('partid' => (int)$setting['partid']); } if(!isset($setting['description'])){ $query .= 'description=NULL,'; } else { $query .= 'description=:description,'; $params[] = array('description' => addslashes($setting['description'])); } $query .= 'host=:host,name=:name,'; $params[] = array('host' => (int)$setting['host']); $params[] = array('name' => $setting['name']); if(!isset($setting['content'])){ $query .= 'content=NULL,'; } else { $query .= 'content=:content,'; $params[] = array('content' => addslashes($setting['content'])); } if(!isset($setting['trigger'])){ $query .= 'trigger=NULL'; } else { $query .= 'trigger=:trigger'; $params[] = array('trigger' => addslashes($setting['trigger'])); } After that, I pass it to a database function: dbQuery($query,$params) The function dbQuery relies on a working PDO Connection and goes like this: function dbQuery($query,$params = array()){ global $DBVARS; // I know that is not very nice ;-) $db = dbInit(); $prefix = isset($DBVARS['table_prefix']) ? $DBVARS['table_prefix']
Search Username Password Remember Me? Register Lost Password? facebook google twitter http://forums.devshed.com/php-development/942635-pdo-sqlstate-hy093-invalid-parameter-parameter-defined-post2867088.html rss Free Web Developer Tools Advanced Search Forum Programming Languages PHP Development PDO: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined http://php.net/manual/en/pdostatement.bindparam.php Thread: PDO: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined Share This Thread Tweet This + 1 this Post To invalid parameter Linkedin Subscribe to this Thread Subscribe to This Thread March 29th, 2013,09:29 PM #1 No Profile Picture etidd View Profile View Forum Posts Visit Homepage Contributing User Devshed Newbie (0 - 499 posts) Join Date May 2009 Location Atlanta, GA, invalid parameter number USA Posts 68 Rep Power 8 PDO: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined Hello all, I have been utterly stumped trying to figure out why I am getting this error about invalid parameter numbers when connecting to mySQL database. Again, the error message is as follows: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined PHP Code: classDatabaseWriter
{
publicfunctionwriteUserToDatabase($email,$name,$age,$gender,$country,$category)
{
$host='**********';
$dbname='emailcollection';