_db_query_callback
Definition
_db_query_callback($match, $init = FALSE)
includes/database.inc, line 200
Description
Helper function for db_query().
Related topics
| Name | Description |
|---|---|
| Database abstraction layer | Allow the use of different database servers using the same code base. |
Code
<?php
function _db_query_callback($match, $init = FALSE) {
static $args = NULL;
if ($init) {
$args = $match;
return;
}
switch ($match[1]) {
case '%d': // We must use type casting to int to convert FALSE/NULL/(TRUE?)
return (int) array_shift($args); // We don't need db_escape_string as numbers are db-safe
case '%s':
return db_escape_string(array_shift($args));
case '%n':
// Numeric values have arbitrary precision, so can't be treated as float.
// is_numeric() allows hex values (0xFF), but they are not valid.
$value = trim(array_shift($args));
return is_numeric($value) && !preg_match('/x/i', $value) ? $value : '0';
case '%%':
return '%';
case '%f':
return (float) array_shift($args);
case '%b': // binary data
return db_encode_blob(array_shift($args));
}
}
?> 