php - What is the error in my PDO syntax -


sorry couldn't come better title. :-(

this first time trying use pdo. have referenced php.net syntax. database empty , looks this:

field         type       null   key default id            int(11)    no     pri null    auto_increment query_string  text       no         null     exclude_count tinyint(4) no         null     

running code should create or update row in pages table, db unchanged.

here's code , output:

$dbuser='abc'; $dbpass='password';  $connection = new pdo('mysql:host=127.0.0.1;dbname=mydb', $dbuser, $dbpass); if(!$connection){echo '<!-- db connection error -->';}else{echo '<!-- db connection confirmed -->';} $connection->begintransaction(); $prep_idcheck=$connection->prepare("select id pages query_string = :origqs"); $prep_idcheck->bindparam(':origqs', $orig_qs); $row=$prep_idcheck->fetch();  if($row)   {     echo '<!-- exdb: have dealt 1 before. -->';     $existing=true;   } else   {     echo '<!-- exdb: new one. -->';     $existing=false;   }  if($existing)   {     $prep_report_excounts=$connection->prepare("update pages set exclude_count = :exclude_count query_string = :origqs");   } else   {     $prep_report_excounts=$connection->prepare("insert pages (exclude_count, query_string) values (:exclude_count,:origqs)");   } $prep_report_excounts->bindparam(':origqs', $orig_qs); $prep_report_excounts->bindparam(':exclude_count', $exclude_count); $status=$prep_report_excounts->execute(); if(!$status)   {    $error=$connection->errorinfo();     echo'<!-- statement did not execute '."\n";     var_dump($error);     echo'-->';   } $connection->commit(); ?> 

output

<!-- db connection confirmed --><!-- exdb: new one. --><!-- statement did not execute  array(1) {   [0]=>   string(5) "00000" } --> 

you missing execute() on $prep_idcheck

$prep_idcheck=$connection->prepare("select id pages query_string = :origqs"); $prep_idcheck->bindparam(':origqs', $orig_qs); // missing execute(); $prep_idcheck->execute(); $row=$prep_idcheck->fetch(); 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -