PHP Velho Oeste 2024

sqlite_array_query

(PHP 5 < 5.4.0, PECL sqlite >= 1.0.0)

sqlite_array_queryExecuta uma query ao banco de dados e retorna uma matriz

Descrição

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 ]] ) : array

sqlite_array_query() é similar a usar sqlite_query() e então sqlite_fetch_array() para cada linha do conjunto de resultados e coloca-lo em uma matriz, como mostrado no exemplo abaixo. Usar sqlite_array_query() é significativamente mais rápido do que usar um script como este.

Exemplo #1 sqlite_array_query() implementado por você mesmo

<?php
$q 
sqlite_query($database"SELECT * from foo LIMIT 100");
$rows = array();
while (
$r sqlite_fetch_array($q)) {
    
$rows[] = $r;
}
?>
Dica

sqlite_array_query() é melhor utilizado para queries que retornam 45 linhas ou menos. Se você tem mais dados do que isto, é recomendado que você escreva os seus script para usar sqlite_unbuffered_query() para ter uma performance melhor.

Veja também sqlite_query(), sqlite_fetch_array() e sqlite_fetch_string().

add a note add a note

User Contributed Notes 1 note

up
0
kendlj at NOSPAM dot web dot de
19 years ago
Do not use this code, whenever you may get no result:

<?
$return_data
=@sqlite_array_query($query,$databaseHandle);
if(!
$return_data)
{
  
//Errorhandling code
  
die( sqlite_error_string( sqlite_last_error($this->databaseHandle) ) );
}
?>

It will execute the Errorhandling code although there is no error, cause if there is nothing found, sqlite_array_query returns an empty array, which is interpreted as 'false' here.
You will get an Message like:
'not an error'

Instead use:

<?
$return_data
=@sqlite_array_query($query,$databaseHandle);
if(
$return_data===false)
{
  
//Errorhandling code
}
?>
To Top