[英]What is difference between '(blank)where' and 'where' in Mysql update query
private function update($fields)
{
$query = 'UPDATE`'.$this->table.'`SET';
foreach ($fields as $key => $value) {
$query .= '`' . $key . '` = :'. $key . ',';
}
$query = rtrim($query, ',');
$query .= ' WHERE `'. $this->primaryKey . '` = :primaryKey';
$fields['primaryKey'] = $fields['id'];
$fields = $this->processDates($fields);
$this->query($query,$fields);
}
I want to make the update method and these codes work.我想让更新方法和这些代码工作。 but when I change
但是当我改变
$query .= ' WHERE `'. $this->primaryKey . '` = :primaryKey';
into进入
$query .= 'WHERE `'. $this->primaryKey . '` = :primaryKey';
, then it doesn't work. ,然后它不起作用。 I guess the only difference is blank in front of WHERE.
我想唯一的区别是 WHERE 前面的空白。
I really don't understand why it doesn't work.我真的不明白为什么它不起作用。
You are appending where clause to update query so without blank your update query is:您将 where 子句附加到更新查询,因此没有空白您的更新查询是:
UPDATE tableName SET columnName = :placeholderWHERE primaryKey = :primaryKey;
With the blank:与空白:
UPDATE tableName SET columnName = :placeholder WHERE primaryKey = :primaryKey;
That is the difference.这就是区别。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.