db_query_temporary
includes/database.mysql.inc, строка 357
- Версии
- 5 – 6
db_query_temporary($query)
Выполняет SELECT-запрос и сохраняет результат во временной таблице.
Use this as a substitute for db_query()
when the results need to stored
in a temporary table. Temporary tables exist for the duration of the page
request.
User-supplied arguments to the query should be passed in as separate parameters
so that they can be properly escaped to avoid SQL injection attacks.
Note that if you need to know how many results were returned, you should do
a SELECT COUNT(*) on the temporary table afterwards. db_num_rows()
and
db_affected_rows()
do not give consistent result across different database
types in this case.
Примечание: использование этого синтаксиса приведет к тому, что NULL
и FALSE
будут превращаться в десятичный 0, а TRUE
в десятичную 1.
Параметры
$query
A string containing a normal SELECT SQL query.
...
A variable number of arguments which are substituted into the query
using printf()
syntax. The query arguments can be enclosed in one
array instead.
Valid %-modifiers are: %s, %d, %f, %b (binary data, do not enclose
in ''
) and %%.
$table
The name of the temporary table to select into. This name will not be
prefixed as there is no risk of collision.
Возвращаемое значение
Результирующий ресурс запроса или FALSE
, если запрос вызвал ошибку.
Связанные темы
Код
<?php
function db_query_temporary($query) {
$args = func_get_args();
$tablename = array_pop($args);
array_shift($args);
$query = preg_replace('/^SELECT/i', 'CREATE TEMPORARY TABLE '. $tablename .' SELECT', 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);
return _db_query($query);
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии