我正在尝试用 0 更新不在我从 xml 获取的数组中的行。
$sus = array();
foreach( $xml->property as $node ) {
$sus[] = $node->suid;
}
$A = "'".implode("','",$sus)."'";
echo $A;
$sth = $dbh->prepare("UPDATE tabla SET alta = 0
WHERE suid NOT IN ($A)");
$sth->execute($sus);
当我 echo $A 时,它会正确打印出来,如下所示: '60','62','65','73','74','79','83','90','112','124' 但它不进行更新, 怎么了?
最佳答案
您应该首先转义 XML 值以避免 SQL 注入(inject):
$escapedValues = str_repeat('?,', count($sus) - 1) . '?';
$sth = $db->prepare("UPDATE tabla SET alta = 0 WHERE suid NOT IN ($escapedValues)"
$sth->execute($sus);
关于php - Mysql,更新不在数组php中的地方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43709318/