function _db_query

6.x database.pgsql.inc _db_query($query, $debug = 0)
6.x database.mysqli.inc _db_query($query, $debug = 0)
6.x database.mysql.inc _db_query($query, $debug = 0)

Helper function for db_query().

Related topics

8 calls to _db_query()
db_query in drupal-6.x/includes/database.pgsql.inc
Runs a basic query in the active database.
db_query in drupal-6.x/includes/database.mysql-common.inc
Runs a basic query in the active database.
db_query_range in drupal-6.x/includes/database.pgsql.inc
Runs a limited-range query in the active database.
db_query_range in drupal-6.x/includes/database.mysqli.inc
Runs a limited-range query in the active database.
db_query_range in drupal-6.x/includes/database.mysql.inc
Runs a limited-range query in the active database.

... See full list

File

drupal-6.x/includes/database.mysqli.inc, line 97
Database interface code for MySQL database servers using the mysqli client libraries. mysqli is included in PHP 5 by default and allows developers to use the advanced features of MySQL 4.1.x, 5.0.x and beyond.

Code

function _db_query($query, $debug = 0) {
  global $active_db, $queries, $user;

  if (variable_get('dev_query', 0)) {
    list($usec, $sec) = explode(' ', microtime());
    $timer = (float) $usec + (float) $sec;
    // If devel.module query logging is enabled, prepend a comment with the username and calling function
    // to the SQL string. This is useful when running mysql's SHOW PROCESSLIST to learn what exact
    // code is issueing the slow query.
    $bt = debug_backtrace();
    // t() may not be available yet so we don't wrap 'Anonymous'
    $name = $user->uid ? $user->name : variable_get('anonymous', 'Anonymous');
    // str_replace() to prevent SQL injection via username or anonymous name.
    $name = str_replace(array('*', '/'), '', $name);
    $query = '/* ' . $name . ' : ' . $bt[2]['function'] . ' */ ' . $query;
  }

  $result = mysqli_query($active_db, $query);

  if (variable_get('dev_query', 0)) {
    $query = $bt[2]['function'] . "\n" . $query;
    list($usec, $sec) = explode(' ', microtime());
    $stop = (float) $usec + (float) $sec;
    $diff = $stop - $timer;
    $queries[] = array($query, $diff);
  }

  if ($debug) {
    print '<p>query: ' . $query . '<br />error:' . mysqli_error($active_db) . '</p>';
  }

  if (!mysqli_errno($active_db)) {
    return $result;
  }
  else {
    // Indicate to drupal_error_handler that this is a database error.
    ${DB_ERROR}= TRUE;
    trigger_error(check_plain(mysqli_error($active_db) . "\nquery: " . $query), E_USER_WARNING);
    return FALSE;
  }
}