* @param string Name of the DB table
* @param array Input array that controls the "WHERE" condition part. Pass it an associative array like array('key1' => 'value1', 'key2' => 'value2') to get a statement like "WHERE key1 = value1 AND key2 = value2". Escaping is done automatically in this function.
* @param array Input array that controls the "SET" condition part. Pass it an associative array like array('key1' => 'value1', 'key2' => 'value2') to get a statement like "SET key1 = value1, key2 = value2". Escaping is done automatically in this function.
+ * @param string What do do with the SQL query (execute, display)
* @return array Returns the result of the SQL query
*/
-function serendipity_db_update($table, $keys, $values)
+function serendipity_db_update($table, $keys, $values, $action = 'execute')
{
global $serendipity;
$where = " WHERE $where";
}
- return serendipity_db_query("UPDATE {$serendipity['dbPrefix']}$table SET $set $where");
+ $q = "UPDATE {$serendipity['dbPrefix']}$table SET $set $where";
+ if ($action == 'execute') {
+ return serendipity_db_query($q);
+ } else {
+ return $q;
+ }
}
/**
* @access public
* @param string Name of the SQL table
* @param array Associative array of keys/values to insert into the table. Escaping is done automatically.
+ * @param string What do do with the SQL query (execute, display)
* @return array Returns the result of the SQL query
*/
-function serendipity_db_insert($table, $values)
+function serendipity_db_insert($table, $values, $action = 'execute')
{
global $serendipity;
$vals .= '\'' . serendipity_db_escape_string($v) . '\'';
}
- return serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}$table ($names) values ($vals)");
+ $q = "INSERT INTO {$serendipity['dbPrefix']}$table ($names) values ($vals)";
+
+ if ($action == 'execute') {
+ return serendipity_db_query($q);
+ } else {
+ return $q;
+ }
}
/**