我有一个简单的方法,它不能正常工作 - 想要使用预处理语句,但不知何故它没有被执行;相反,原始查询工作正常。
可能是什么问题?我应该将一些额外的args传递给pdo方法吗?
$_POST['sequence'] = [
0 => 2,
1 => 1
];
if (!empty($_POST['sequence'])) {
$query = '
UPDATE '.$this->db->backtick($this->controller->table).'
SET `sequence` = CASE `id`'
;
foreach ($_POST['sequence'] as $sequence => $id) {
$values[':id'.$id] = $id;
$values[':sequence'.$sequence] = $sequence;
$query .= ' WHEN :id'.$id.' THEN :sequence'.$sequence;
}
$values[':ids'] = implode(',', array_values($_POST['sequence']));
$query .= ' END WHERE `id` IN (:ids)';
$statement = $this->db->handle->prepare($query);
$statement->execute($values); //doesn't work
//$query2 = str_replace(array_keys($values), array_values($values), $query);
//$this->db->handle->query($query2); works
}
答案 0 :(得分:0)
不要将IN
$query .= ' END WHERE `id` IN ('.implode(',', array_values($_POST['sequence'])).')';