![](/img/trans.png)
[英]How can I insert a lot of records into database all at once from a textarea where every line of it is a record?
[英]Insert a lot of records into database
我有一個包含很多(500+)代碼的列表,我想將其插入數據庫。
例如:用戶給textarea指定的代碼,代碼用換行符( \\n
)分隔。 在PHP中,它是$_POST['codes']
。 當然,我可以只使用explode()
函數並在循環中插入所有代碼,但是我認為500次重復並不是一個好主意。
那么,如何才能做到最好呢?
如果您擔心單獨插入的數量,則可以根據數據的大小將其全部放入一個查詢中:
mysql_query("INSERT INTO mytable(`People`, `Places`, `Ideas`, `things`)
VALUES ('40', '15', '0', '0'),
('0', '5', '10', '0'),
('10', '0', '11', '12')");
(示例來自: https : //stackoverflow.com/a/10286687/486780 )
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.