我正在创建更新数据库方法,并且所有内容都按照它应该的方式工作,除非当我尝试将'updated'=> NOW()添加到$ updateArray()。很明显,PDO会清理数据库中的离开0000-00-00的mysql函数。如何将MySQL NOW()函数从数组传递到清理值
public function update($table, $id, $updateArray) {
$valuesArray = array_values($updateArray);
$valuesArray[] = $id;
foreach ($updateArray as $col => $value) {
$values .= "$col = ?, ";
}
$values = substr($vals, 0, -2);
$query = $this->handle->prepare("UPDATE $table SET $values WHERE id = ?");
return $query->execute($valuesArray);
}
$updateArray = ['title' => $_POST["title"], 'label' => $_POST["label"], 'body' => $_POST["body"], 'updated' => 'NOW()'];
$db->update('pages', $_POST["id"], $updateArray);
什么是最好的方法来得到这个?我所有的想法都非常黑客。
把你的SQL结构的数据类型问题。 –