簡體   English   中英

在同一查詢中多次插入?

[英]Multiple insert in the same query?

我該如何改善? 這看起來太可怕了。

$db->query("INSERT INTO items (player_id, sid, pid, itemtype, count, attributes) VALUES (".$db->lastInsertId().", 101, 1, 2460, 1, '')");
$db->query("INSERT INTO items (player_id, sid, pid, itemtype, count, attributes) VALUES (".$db->lastInsertId().", 102,3,1988,1,'')");
$db->query("INSERT INTO items (player_id, sid, pid, itemtype, count, attributes) VALUES (".$db->lastInsertId().", 103,4,2465,1,'')");
$db->query("INSERT INTO items (player_id, sid, pid, itemtype, count, attributes) VALUES (".$db->lastInsertId().", 104,5,2511,1,'')");
$db->query("INSERT INTO items (player_id, sid, pid, itemtype, count, attributes) VALUES (".$db->lastInsertId().", 105,6,2394,1,'')");
$db->query("INSERT INTO items (player_id, sid, pid, itemtype, count, attributes) VALUES (".$db->lastInsertId().", 106,7,2478,1,'')");
$db->query("INSERT INTO items (player_id, sid, pid, itemtype, count, attributes) VALUES (".$db->lastInsertId().", 107,8,2643,1,'')");
$db->query("INSERT INTO items (player_id, sid, pid, itemtype, count, attributes) VALUES (".$db->lastInsertId().", 108,10,2050,1,'')");
$db->query("INSERT INTO items (player_id, sid, pid, itemtype, count, attributes) VALUES (".$db->lastInsertId().", 109,102,2120,1,'')");
$db->query("INSERT INTO items (player_id, sid, pid, itemtype, count, attributes) VALUES (".$db->lastInsertId().", 110,102,2554,1,'')");

手冊

使用VALUES語法的INSERT語句可以插入多行。 為此,請包括多個列值列表,每個列值括在括號內並用逗號分隔。

您還將對player_id列使用自動遞增 ,以使其起作用。

$db->query("INSERT INTO items (sid, pid, itemtype, count, attributes) 
VALUES (101, 1, 2460, 1, ''),
(102,3,1988,1,''),
(103,4,2465,1,'')");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM