0
我不知道如何通过使用PDO更新或插入多行。请帮帮我。(PDO PHP)更新或插入多行的最快方法?
的东西是在我心目中是:
$stmt = $dbh->query("update_line_1; update_line_2; update_line_3");
//update_line_1: update table a set a.column1 = "s1" where a.id = 1
//update_line_2: update table a set a.column1 = "s2" where a.id = 2
//....
$stm = $dbh->query("insert_line_1; insert_line_3; insert_line_3");
//something is like the update line above.
我不知道这样的工作与否。如果您有其他方法,请告诉我。非常感谢你。
如果我使用准备语句,我只是每次更新每一行。 (这比上述更安全)
$stmt = $dbh->prepare("update table a set a.colum1 = :column1 where a.id = :id");
$stmt->bindParam(":column1","s1");
$stmt->bindparam(":id",1);
$stmt->execute();
最讨厌的事情,我不想使用循环来经过数组中的所有元素,并更新或每次插入每个元素
是群集安全更新或插入多行到数据库的另一种方法?感谢您的帮助。
对不起,我的英语。
希望有个更好的答案。 – user3883314
@ user3883314你希望做什么更好?没有办法大规模更新您尝试使用不同WHERE条件定位的多行。该功能根本不存在。 –
@ user3883314这是一个很好的答案... –