public function update($tablename, $data, $filter, $filterBindings = null, $useMaster = true)
{
// Check for filter bindings
if (is_array($filterBindings)) {
// Check if there are any binding conflicts between $data and $filterBindings
$conflicts = array_intersect_key($data, $filterBindings);
if (count($conflicts) > 0) {
$this->errorCode = 'n/a';
$this->errorMsg = 'Duplicate bindings for data and filter (' . implode(', ', array_keys($conflicts)) . ').';
return -2;
}
} elseif (!is_null($filterBindings)) {
// Invalid filter binding specification, must be an array or null
$this->errorCode = 'n/a';
$this->errorMsg = 'Invalid filter binding passed, must be an array or null.';
return -3;
}
// Add backticks to table name
$tablename = '`' . str_replace('.', '`.`', trim($tablename, '"\'`')) . '`';
$query = 'UPDATE ' . $tablename . ' SET ';
$setList = array();
// Build "set" update string and Add proper name binding prefix to binding array
$setList = array();
foreach ($data as $field => $val) {
$setList[] = '`' . $field . '`= :' . $field;
}
$query .= implode(', ', $setList) . ' WHERE ' . $filter;
// Check if we need to add filter bindings
if (is_array($filterBindings)) {
$data = array_merge($data, $filterBindings);
}
$this->prepare($query, $useMaster);
return $this->execute($data, $useMaster);
}