(PHP 5 < 5.4.0, PECL sqlite >= 1.0.0)
sqlite_array_query -- SQLiteDatabase::arrayQuery — Execute a query against a given database and returns an array
$dbhandle
, string $query
[, int $result_type
= SQLITE_BOTH
[, bool $decode_binary
= true
]] )$query
, resource $dbhandle
[, int $result_type
= SQLITE_BOTH
[, bool $decode_binary
= true
]] )物件導向風格 (method):
$query
[, int $result_type
= SQLITE_BOTH
[, bool $decode_binary
= true
]] )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.
Data inside the query should be properly escaped.
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
參數作為函式的第一個參數。
Returns an array of the entire result set; FALSE
otherwise.
由
SQLITE_ASSOC
和 SQLITE_BOTH
回傳的欄名會根據
sqlite.assoc_case
設定選項的值來決定大小寫。
Example #1 程序化風格
<?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'];
}
?>