Sunday, 15 June 2014

php - mysql PDO multi parameter insert statement -



php - mysql PDO multi parameter insert statement -

i dont know wrong.. i've seen lot of different ways it, can 1 tell me hell wrong this.. throwing error "error: sqlstate[42000]: syntax error or access violation: 1064 have error in sql syntax; check manual corresponds mysql server version right syntax utilize near 'desc) values ('30.59','blue shirt','a cool bluish shirt')' @ line 1". have tried multiple ways , same result..

<?php $title = 'blue shirt'; $desc = 'a cool bluish shirt'; $price = 30.59; $user = 'foo'; $pass = 'bar'; try{ $conn = new pdo('mysql:host=examplehost;dbname=exampledb_name',$user,$pass); $conn->setattribute(pdo::attr_errmode, pdo::errmode_exception); if(!$conn){ echo"couldnt connect db"; }else { echo 'connected boss!!' . '<br>'; $stmt = $conn->prepare("insert 68_items (price, title, desc) values (:price,:title,:desc)"); if(!$stmt->execute(array( ':price' => $price, ':title' => $title, ':desc' => $desc)) ) { echo'statment failed'; }else { echo 'statment success, ' . $stmt->rowcount() . 'rows affected.'; } } } grab (pdoexception $e) { echo 'error: ' . $e->getmessage(); } ?>

desc reserved word in mysql should utilize backticks escape it:

"insert 68_items (price, title, `desc`) values (:price,:title,:desc)"

php mysql pdo

No comments:

Post a Comment