我正在尝试创建一个更新查询,并且我正在将一些设置的内容循环到一个名为$str的var中,我似乎无法使其正常工作。
if (is_numeric($id)) {
if (!empty($values) && !empty($table_name)) {
$str = '';
$sql = "UPDATE `$table_name` SET :update_values WHERE `$column_name` = :id";
// Its one because we dont use ID like that
$i = 1;
foreach ($values as $key => $value) {
if ($key != $column_name) {
// Exclude the last one from having a comma at the end
if ($i == count($values) - 1) {
$str .= "$key='" . $value . "'";
} else {
$str .= "$key='" . $value . "', ";
$i++;
}
}
}
$query = $this->dbh->prepare($sql);
$query->bindValue('update_values', $str, PDO::PARAM_STR);
$query->bindValue(':id', $id, PDO::PARAM_INT);
$query->execute();
return true;
} else {
return false;
}
} else{
return false;
}
}
输出:
致命错误: 未捕获的 PDO异常: SQLSTATE[42000]: 语法错误或访问冲突: 1064 您的 SQL 语法中存在错误;检查与您的 MariaDB 服务器版本对应的手册,了解在第 1 行note_name=\'yeet'附近使用的正确语法,note_date=\'2020-02-20\',note_desc=\'asdasdadsdadsdasdad
我是否犯了任何明显的错误?
同样,对于我的生活,我不知道值前面的反斜杠是什么意思。
慕雪6442864