我正在尝试使用此代码更新某些数据库值
public function updateImprovement($id, $improveId, $body) {
//UPDATE ITC
$update = ("UPDATE as_improvement SET value = :value WHERE id = :id");
$statement = $this->db-> prepare($update);
$statement -> bindValue( ":id", $id, PDO::PARAM_STR );
$statement -> bindValue( ":value", $body, PDO::PARAM_STR );
$statement -> execute();
//UPDATE IMPROVE
$update = ("UPDATE as_improve SET content_new = :content_new AND approved = 1 WHERE id = :improveId");
$statement = $this->db-> prepare($update);
$statement -> bindValue( ":improveId", $improveId, PDO::PARAM_STR );
$statement -> bindValue( ":content_new", $body, PDO::PARAM_STR );
$statement -> execute();
}
问题在于“content_new” - > (content_new =:content_new)变量,因为没有它,sql语句就完美地执行了。我可以用两句话两次使用$ body吗?
答案 0 :(得分:0)
您正在运行content_new = :content_new AND approved = 1
应该是:content_new = :content_new, approved = 1
但是,我已经为你做了一点回事:
public function updateImprovement($id, $improveId, $body) {
//UPDATE ITC
$update = ("UPDATE as_improvement SET value = ? WHERE id = ?");
$statement = $this->db-> prepare($update);
$statement->execute([$body, $id]);
//UPDATE IMPROVE
$update = ("UPDATE as_improve SET content_new = ?, approved = 1 WHERE id = ?");
$statement = $this->db-> prepare($update);
$statement->execute([$body, $improveId]);
}