function update($table, $keyvalues, $values = array(), $clauses = '') { global $dbutils_history_callback; global $dbutils_show_errors; global $dbutils_link; assertDataNonRO('update:' . $table); $r = false; if ($dbutils_history_callback !== false) { txBegin(); } $sql = 'UPDATE `' . $table . '` SET ' . arraytosafe($values) . ' WHERE ' . arraytosafe($keyvalues, true); if (is_array($clauses)) { $clauses = qsafe($clauses); } if ($clauses > '') { $sql .= ' ' . $clauses; } mysql_query($sql, $dbutils_link); $error = mysql_error($dbutils_link); if ($error > '') { if ($dbutils_show_errors) { echo $error . "\r\n"; } } else { $r = mysql_affected_rows($dbutils_link); } if ($dbutils_history_callback !== false) { $dbutils_history_callback($table, $keyvalues); txCommit(); } return $r; }
function update($table = '', $keyvalues = array(), $values = array(), $clauses = '', $stack_trace_level = 0) { global $dbutils_history_callback; global $dbutils_show_errors; global $dbutils_link; if ('' . @$table == '') { dbiutils_stack_trace('No table specified', $stack_trace_level); return false; } if (!is_array($keyvalues)) { dbiutils_stack_trace('Match criteria must be specified as an array', $stack_trace_level); return false; } if (count($keyvalues) == 0) { dbiutils_stack_trace('No match criteria specified', $stack_trace_level); return false; } if (!dbiutils_assert_connection(0)) { return false; } assertDataNonRO('update:' . $table); $r = false; $valuestoset = arraytosafe($values); if ($valuestoset == '') { dbiutils_stack_trace('No values specified', $stack_trace_level); return false; } if ($dbutils_history_callback !== false) { txBegin(); } $sql = 'UPDATE `' . $table . '` SET ' . $valuestoset . ' WHERE ' . arraytosafe($keyvalues, true); if (is_array($clauses)) { $clauses = '' . @qsafe($clauses, 1 + @$stack_trace_level); } if ($clauses > '') { $sql .= ' ' . $clauses; } mysqli_query($dbutils_link, $sql); $error = mysqli_error($dbutils_link); if ($error > '') { if ($dbutils_show_errors) { dbiutils_stack_trace('MySQL: ' . $error . ' [QUERY: ' . $sql . ']', $stack_trace_level); } if ($dbutils_history_callback !== false) { txCancel(); } return false; } $r = mysqli_affected_rows($dbutils_link); if ($dbutils_history_callback !== false) { $dbutils_history_callback($table, $keyvalues); if (!txCommit()) { // if the commit fails, the history callback's changes should be rolled back too. return false; } } return $r; }