我尝试使用pdo制作准备好的statament。可以将几个更新放在atonce?
例如:
sql1 = "Update product set large = '1large' where id = 1";
sql2 = "Update product set large = '2large' where id = 2";
sql3 = "Update product set large = '3large' where id = 3";
如何在Pdo中准备sql1,sql2 .... sqlN来执行得更快? 我找到了一个例子,但它逐行工作(sql1,sql2 ....)
<?php
$stmt = $dbh->prepare("UPDATE product SET large = ':large' WHERE id = ':id'");
$stmt->bindParam(':id', $id, PDO::PARAM_STR);
$stmt->bindParam(':large', $large, PDO::PARAM_STR);
$stmt->execute();
?>
答案 0 :(得分:-1)
与可以分组为单个语句的插入不同,更新特定于数据库中的现有条目。
根据您所做的更广泛的背景,您可能会发现使用CASE,WHEN,THEN的批量更新感兴趣的问题: