The usage of sqlite_fetch_all should be your choise
(instead the well known practice of "while()" loop)
when unmodified tabledata is prefered.
Example code for a better illustration:
<?php
if ($dbhandle = sqlite_open('mysqlitedb', 0666, $sqliteerror)):
$query = "SELECT x, y FROM sometable LIMIT 3;";
$result = sqlite_query($dbhandle, $query);
// usage with sqlite_fetch_all
$array1 = sqlite_fetch_all($result, SQLITE_ASSOC);
// the "well known practice"
$i = '0';
while ($row = sqlite_fetch_array($result, SQLITE_ASSOC)):
$array2["$i"] = $row;
$i++;
endwhile;
sqlite_close($dbhandle);
endif;
?>
There are no differents within the values of array1 and array2.
Both arrays will be something like:
Array
(
[0] => Array
(
[x] => 22004
[y] => example_data1
)
[1] => Array
(
[x] => 92044
[y] => example_data2
)
[2] => Array
(
[x] => 143060
[y] => example_data3
)
)
If you want to let me know about your comments, feel
free to send me a note via feedback-formular at:
http://www.d0x.de/pages/kontakt.php
sqlite_fetch_all
SQLiteResult::fetchAll
SQLiteUnbuffered::fetchAll
(PHP 5 < 5.4.0, PECL sqlite >= 1.0.0)
sqlite_fetch_all -- SQLiteResult::fetchAll -- SQLiteUnbuffered::fetchAll — Scarica tutte le righe di un risultato in un array di array
Descrizione
$result
[, int $result_type = SQLITE_BOTH
[, bool $decode_binary = true
]] )Stile orientato agli oggetti (metodo):
$result_type = SQLITE_BOTH
[, bool $decode_binary = true
]] )$result_type = SQLITE_BOTH
[, bool $decode_binary = true
]] )
sqlite_fetch_all() restituisce un array con l'intero set di risultati
dalla risorsa result. È simile ad eseguire
sqlite_query() (oppure
sqlite_unbuffered_query()) e quindi
sqlite_fetch_array() per ciascuna riga del set di risultati.
Elenco dei parametri
-
result -
Risorsa SQLite. Questo parametro non è richiesto quando si usa il metodo ad oggetti.
-
result_type -
Il parametro opzionale
result_typeaccetta una costante e determina come l'array restituito sarà indicizzato. UsandoSQLITE_ASSOCrestituirà solo indici associativi (campi nominali) mentreSQLITE_NUMrestituirà solo indici numerici (campi numerici ordinali).SQLITE_BOTHrestituirà sia gli indici associativi che numerici.SQLITE_BOTHè il default per questa funzione. -
decode_binary -
Quando
decode_binaryè impostato aTRUE(per default), il PHP decodificherà i dati binari se questi furono codificati con la funzione sqlite_escape_string(). Normalmente si dovrebbe lasciare inalterato il comportamento di default, a meno che non si debba intervenire su database creati da altre applicazioni SQLite.
Valori restituiti
Restituisce un array delle righe rimanenti da un set di risultati. Se è chiamata dopo sqlite_query(), restituisce tutte le righe. Se è chiamata dopo sqlite_fetch_array(), restituisce il resto. Se non ci sono righe da un set di risultati, restituisce un array vuoto.
I nomi delle colonne restituiti da
SQLITE_ASSOC e da SQLITE_BOTH saranno
maiuscoli o minuscoli in base al valore del parametro di configurazione
sqlite.assoc_case
.
Esempi
Example #1 Esempio procedurale
<?php
$dbhandle = sqlite_open('sqlitedb');
$query = sqlite_query($dbhandle, 'SELECT name, email FROM users LIMIT 25');
$result = sqlite_fetch_all($query, SQLITE_ASSOC);
foreach ($result as $entry) {
echo 'Name: ' . $entry['name'] . ' E-mail: ' . $entry['email'];
}
?>
Example #2 Esempio ad oggetti
<?php
$dbhandle = new SQLiteDatabase('sqlitedb');
$query = $dbhandle->query('SELECT name, email FROM users LIMIT 25'); // set di risultati bufferizzato
$query = $dbhandle->unbufferedQuery('SELECT name, email FROM users LIMIT 25'); // elimino dal buffer il set di risultati
$result = $query->fetchAll(SQLITE_ASSOC);
foreach ($result as $entry) {
echo 'Name: ' . $entry['name'] . ' E-mail: ' . $entry['email'];
}
?>
