Skip to content

Instantly share code, notes, and snippets.

@hugowetterberg
Created January 26, 2009 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hugowetterberg/52779 to your computer and use it in GitHub Desktop.
Save hugowetterberg/52779 to your computer and use it in GitHub Desktop.
update_sql function with support for parameters
/**
* Had to reimplement the update_sql function to be
* able to pass serialized php into the db, otherwise
* the {}:s were prefixed as tables.
*
* This implementation is a merge of update_sql and
* db_query to get the near-actual executed sql for the log.
*
* Two sql-statements have to be generated, one with the
* table prefixes for execution and one with the enclosing
* {}:s for tables preserved to match the standard update_sql
* output.
*
* @see db_query
* @see update_sql
*
* @param string $query
*/
function _update_sql_with_param_support($query) {
$args = func_get_args();
array_shift($args);
$prefixed_query = db_prefix_tables($query);
if (isset($args[0]) and is_array($args[0])) { // 'All arguments in one array' syntax
$args = $args[0];
}
_db_query_callback($args, TRUE);
$query = preg_replace_callback(DB_QUERY_REGEXP, '_db_query_callback', $query);
_db_query_callback($args, TRUE);
$prefixed_query = preg_replace_callback(DB_QUERY_REGEXP, '_db_query_callback', $prefixed_query);
$result = _db_query($prefixed_query);
return array('success' => $result !== FALSE, 'query' => check_plain($query));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment