检查完所有其他stackoverflow后,有相同问题的Google帖子找不到解决方法。
我正在使用pdo和php,并且正在尝试更新表中的条目。 可能是代码其他部分的问题,但看起来与MYSQL有关。
这里是完整的消息;
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error i n your SQL syntax; check the manual that corresponds to your MariaDB server vers ion for the right syntax to use near '('eggs','scrambled') WHERE (test@12.com)' at line 1< /pre>My code:
Insert.php
public function newInputs(array $input_data) { $this->db->update('cli', [ 'Food' => $input_data['newfood'], 'Comment' =>$input_data['newcomment'] ] , [ 'email' =>$input_data['email'] ]); echo "Data updated"; }
Database.php
public function update(string $table, array $data, array $where){ // array_keys(Returns all the keys of an array) $keys = array_keys($data); $placeholders = preg_filter('/^/', ':', $keys); # $email = preg_filter('/^/', ':', $data['email']); try { $query = $this->conn->prepare("UPDATE $table SET (" . implode(',', $placeholders) . ") WHERE (" . implode(',', $where) . ")"); $query->execute($data); } catch (PDOException $e) { die("<pre>" . $e->getMessage() . "</pre>"); } }
拉近距离