1 回答

TA貢獻(xiàn)1805條經(jīng)驗 獲得超9個贊
插入 3000 行并不是很多,如果操作正確的話,應(yīng)該不會花費(fèi)太多時間。您必須記住,您應(yīng)該始終使用準(zhǔn)備好的語句。您可以使用不同的數(shù)據(jù)多次執(zhí)行同一語句。當(dāng)你將整個事情包裝在一個事務(wù)中時,它應(yīng)該執(zhí)行得非???。
// Start transaction
$mysqli->begin_transaction();
// prepared statement prepared once and executed multiple times
$insertStatement = $mysqli->prepare('INSERT INTO crbsms_queue(sender, phone, message, user_id, time_submitted) VALUES(?,?,?,?,?)');
$insertStatement->bind_param('sssss', $sender, $phone, $message, $user_id, $date);
foreach ($phones as $phone) {
? ? $insertStatement->execute();
}
// Save and end transaction
$mysqli->commit();
如果這不能提高性能,則意味著您在其他地方遇到了問題。您需要分析和調(diào)試您的應(yīng)用程序以找出問題的根源。
附注:請記住啟用 mysqli 錯誤報告,否則您的事務(wù)可能無法正常運(yùn)行。
- 1 回答
- 0 關(guān)注
- 107 瀏覽
添加回答
舉報