在 PHP PDO MYSQL 中插入多行的最佳方法是什么?
问题描述
比如说,我们要在一个表中插入多行:
Say, we have multiple rows to be inserted in a table:
使用 PDO:
现在,您应该如何继续插入行?像这样吗?
Now, how should you proceed in inserting the rows? Like this?
或者,像这样?
哪种方式会更快更安全?插入多行的最佳方法是什么?
Which way would be faster and safer? What is the best way to insert multiple rows?
推荐答案
您至少有以下两个选择:
You have at least these two options:
正如你所看到的,第一个版本有很多简单的代码;但是第二个版本确实执行批量插入.批量插入应该更快,但我同意 @BillKarwin 在绝大多数实现中不会注意到性能差异.
As you can see the first version features a lot simpler code; however the second version does execute a batch insert. The batch insert should be faster, but I agree with @BillKarwin that the performance difference will not be noticed in the vast majority of implementations.
这篇关于在 PHP PDO MYSQL 中插入多行的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!