Unknown table 'table_name' in MULTI DELETE
你的PHP应用在使用PDO执行多表删除操作时遇到了表不存在的问题:
'pdo_code' => '42S02',
'db_code' => 1109,
'db_error' => 'Unknown table \'table_name\' in MULTI DELETE'
$sql = "DELETE users, orders FROM users
INNER JOIN orders ON users.id = orders.user_id
WHERE users.status = 'inactive' AND orders.ordrs.status = 'pending'";
$sql = "DELETE users, orders FROM users
INNER JOIN orders ON users.id = orders.user_id
WHERE users.status = 'inactive' AND orders.status = 'pending'";
function tableExists($pdo, $tableName) {
try {
$result = $pdo->query("SELECT 1 FROM `{$tableName}` LIMIT 1");
return $result !== false;
} catch (PDOException $e) {
return false;
}
}
$tablesToCheck = ['users', 'orders'];
foreach ($tablesToCheck as $table) {
if (!tableExists($pdo, $table)) {
throw new Exception("表 '{$table}' 不存在");
}
}
$sql = "DELETE users, orders FROM users
INNER JOIN orders ON users.id = orders.user_id
WHERE users.status = 'inactive' AND orders.status = 'pending'";
$pdo->exec($sql);