我正在尝试开始使用PDO并遇到一些麻烦.这是我的原始代码:
$query = "
UPDATE `products`
SET `product_qty` = '{$_GET['product_qty']}'
WHERE `product_id` = '{$_GET['product_id']}'
";
mysql_query($query) or die(mysql_error());
Run Code Online (Sandbox Code Playgroud)
这工作正常,但当我尝试将其转换为PDO语法时:
$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();
}
Run Code Online (Sandbox Code Playgroud)
我收到错误:
致命错误:在...中调用未定义的方法PDO :: execute()
有人可以帮助我让我的第一个PDO查询工作吗?
具有该方法的$db->prepare()返回a .PDOStatementexecute()
$stmt = $db->prepare('UPDATE products
SET product_qty = :product_qty
WHERE product_id = :product_id');
$stmt->execute(array(
':product_qty' => $_GET['product_qty'],
':product_id' => $_GET['product_id']
));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1357 次 |
| 最近记录: |