Forum und email

sqlite_array_query

SQLiteDatabase->arrayQuery

(No version information available, 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):

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.

Tip

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 程式建立的資料庫時。

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

Return值

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

SQLITE_ASSOCSQLITE_BOTH 回傳的欄名會根據 sqlite.assoc_case 設定選項的值來決定大小寫。

範例

Example#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'];
}
?>

Example#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'];
}
?>