I’m trying to get started with PDO and am having some trouble. Here’s my original code:
$query = "
UPDATE `products`
SET `product_qty` = '{$_GET['product_qty']}'
WHERE `product_id` = '{$_GET['product_id']}'
";
mysql_query($query) or die(mysql_error());
That works fine, but when I try to translate that to PDO syntax:
$db->prepare('
UPDATE products
SET product_qty = :product_qty
WHERE product_id = :product_id
');
try
{
$db->execute(array(':product_qty' => $_GET['product_qty'], ':product_id' => $_GET['product_id']));
}
catch (PDOException $e)
{
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
I get the error:
Fatal error: Call to undefined method PDO::execute() in …
Could someone help me get my first PDO query working?
The
$db->prepare()returns aPDOStatementwhich has theexecute()method.