sqlite_array_query

(PHP 5)

sqlite_array_query

(no version information, might be only in CVS)

SQLiteDatabase->arrayQuery -- Execute a query against a given database and returns an array

說明

array sqlite_array_query ( resource dbhandle, string query [, int result_type [, bool decode_binary]] )

array sqlite_array_query ( string query, resource dbhandle [, int result_type [, bool decode_binary]] )

Object oriented style (method):

class SQLiteDatabase {

array arrayQuery ( string query [, int result_type [, bool decode_binary]] )

}

sqlite_array_query() executes the given query and returns an array of the entire result set. It is similar to calling sqlite_query() and then sqlite_fetch_array() for each row in the result set. sqlite_array_query() is significantly faster than the aforementioned.

提示: sqlite_array_query() is best suited to queries returning 45 rows or less. If you have more data than that, it is recommended that you write your scripts to use sqlite_unbuffered_query() instead for more optimal performance.

參數

query

The query to be executed.

dbhandle

The SQLite Database resource; returned from sqlite_open() when used procedurally. This parameter is not required when using the object-oriented method.

result_type

可選的 result_type 參數接受一個常量並決定返回的陣列如何索引。用 SQLITE_ASSOC 只會返回關聯索引(有名稱欄位)而 SQLITE_NUM 只會返回數字索引(有序欄位數)。SQLITE_BOTH 會同時返回關聯和數字索引。 SQLITE_BOTH 是本函數的預設值。

decode_binary

decode_binary 參數設為 TRUE(預設值)時,PHP 將解碼那些由 sqlite_escape_string() 編碼的資料。通常應保留此值為其預設值,除非在動作其它支援 sqlite 程式建立的資料庫時。

注: 為相容其它資料庫(例如 MySQL),支援另兩種替代的語法。推薦用第一種,dbhandle 參數作為函數的第一個參數。

返回值

Returns an array of the entire result set; FALSE otherwise.

SQLITE_ASSOCSQLITE_BOTH 返回的列名會根據 sqlite.assoc_case 配置選項的值來決定大小寫。

範例

例子 1. Procedural style

<?php
$dbhandle 
sqlite_open('sqlitedb');
$result sqlite_array_query($dbhandle'SELECT name, email FROM users LIMIT 25'SQLITE_ASSOC);
foreach (
$result as $entry) {
    echo 
'Name: ' $entry['name'] . '  E-mail: ' $entry['email'];
}
?>

例子 2. Object-oriented style

<?php
$dbhandle 
= new SQLiteDatabase('sqlitedb');
$result $dbhandle->arrayQuery('SELECT name, email FROM users LIMIT 25'SQLITE_ASSOC);
foreach (
$result as $entry) {
    echo 
'Name: ' $entry['name'] . '  E-mail: ' $entry['email'];
}
?>