使用 MySQL PHP 更新批量项目

Update Bulk Items with MySQL PHP

我试图用一个单一的批量查询更新我的数据库 table 中的 3,000 多条记录,但是我 运行 进入了一个带有我的 id 数组的路障。想知道我在这里做错了什么?

这是我收到的错误:

check the manual that corresponds to your MySQL server version for the right syntax to use near ') END WHERE InventoryID IN (recs8AFaXZWvAlDIP,recvwDSutfQ66Jtj8,recQ1LODI7ED1FRT'

代码如下:

$sql_connect = mysqli_connect("blah", "blah", "blah", "blah");

$sql = "SELECT inventory.MCategoryID, inventory.InventoryID, inventory.SCategoryID, inventory.ManufacturerID, maincategory.CategoryName as mainCategoryNameMatch, subcategory.SubCategoryName as subCategoryNameMatch, manufacturer.ManufacturerName as manufacturerNameMatch FROM inventory LEFT JOIN maincategory ON inventory.MCategoryID = maincategory.AirTableID LEFT JOIN subcategory ON inventory.SCategoryID = subcategory.AirTableSubCategoryID LEFT JOIN manufacturer ON inventory.ManufacturerID = manufacturer.AirTableManufacturerID ORDER BY CambridgeID";
$doit = mysqli_query($sql_connect, $sql) or die(mysqli_error($sql_connect));
$updateSQL = '';
$uniqueIDArray = [];
$bulkUpdate = '';
$bulkID = '';
while($results = mysqli_fetch_object($doit)){
    $mainCategoryNameResult = $results->mainCategoryNameMatch;
    $subCategoryNameResult = $results->subCategoryNameMatch;
    $manufacturerNameResult = $results->manufacturerNameMatch;
    $uniqueID = $results->InventoryID;      
    $uniqueIDArray[] = $uniqueID;


    $updateSQL .= "WHEN '$uniqueID' THEN '$mainCategoryNameResult'\n";


}
//echo $updateSQL;
$id_list = implode(',', $uniqueIDArray);    
echo "UPDATE inventory SET MainCategoryNameMatch = (CASE InventoryID $updateSQL END) WHERE InventoryID IN ($id_list)<br/>";
if (mysqli_query($sql_connect, "UPDATE inventory SET MainCategoryNameMatch = (CASE InventoryID $updateSQL) WHERE InventoryID IN ($id_list)") or die(mysqli_error($sql_connect))){
    echo $updateSQLStatement;
}   

如有任何帮助,我们将不胜感激。

ID 是字符串 - 它们必须用引号引起来:

$id_list = '"' . implode('","', $uniqueIDArray) . '"';