When I try to update my values it gives me the following error: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined. This only occurs with special characters, for instance: (hello;) and not with (hello) For some reason it can't find values with special characters and I can only insert them and not update or remove it from my database.
And the database is already set on utf8.
public function update($data, $key, $value) {
try {
$this->query = 'UPDATE ' . $this->table . ' SET ';
array_walk($data, function($index, $key) {
$this->query .= $key . ' = ' . ':' . $key . ', ';
});
$this->query = rtrim($this->query, " ,");
$this->query .= " WHERE $key = :$value";
$stmt = $this->db->prepare($this->query);
$stmt->execute(array_merge($data, array($value => $value)));
return true;
} catch(PDOException $e) {
echo $e->getMessage();
}
}
An example how I use it:
if(isset($oldValue, $newValue)) {
$data['database']->update(array("name" => $newValue), "name", $oldValue);
}
The array is to give a key and a new value to update and after the comma is to search for the value in the table 'name'.
If someone knows a solution for this then I would be very happy, thanks in advance.