PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

sqlite_fetch_column_types> <sqlite_fetch_all
Last updated: Fri, 22 Aug 2008

view this page in

sqlite_fetch_array

SQLiteResult->fetch

SQLiteUnbuffered->fetch

(PHP 5, PECL sqlite:1.0-1.0.3)

sqlite_fetch_array -- SQLiteResult->fetch -- SQLiteUnbuffered->fetchObtiene la siguiente fila del resultado en forma de matriz

Descripción

array sqlite_fetch_array ( resource $manejador_resultado [, int $tipo_resultado [, bool $decodificar_binario ]] )

Método que sigue el estilo orientado a objetos:

SQLiteResult
array fetch ([ int $tipo_resultado [, bool $decodificar_binario ]] )
SQLiteUnbuffered
array fetch ([ int $tipo_resultado [, bool $decodificar_binario ]] )

Obtiene la siguiente fila del resultado identificado mediante el parámetro manejador_resultado . Si no existen mas filas, devuelve FALSE, en cualquier otro caso, devuelve una matriz asociativa que contiene los datos de la fila.

Lista de parámetros

manejador_resultado

El identificador del resultado de SQLite. Este parámetro no es obligatorio cuando se emplea el método orientado a objetos.

tipo_resultado

The optional result_type parameter accepts a constant and determines how the returned array will be indexed. Using SQLITE_ASSOC will return only associative indices (named fields) while SQLITE_NUM will return only numerical indices (ordinal field numbers). SQLITE_BOTH will return both associative and numerical indices. SQLITE_BOTH is the default for this function.

decodificar_binario

When the decode_binary parameter is set to TRUE (the default), PHP will decode the binary encoding it applied to the data if it was encoded using the sqlite_escape_string(). You should normally leave this value at its default, unless you are interoperating with databases created by other sqlite capable applications.

Valores retornados

Devuelve una matriz con los datos de la siguiente fila del resultado o FALSE si la siguiente posición se encuentra más allá de la última fila.

The column names returned by SQLITE_ASSOC and SQLITE_BOTH will be case-folded according to the value of the sqlite.assoc_case configuration option.

Ejemplos

Example #1 Ejemplo no orientado a objetos

<?php
$manejador_bd 
sqlite_open('sqlitedb');
$consulta sqlite_query($manejador_bd'SELECT nombre, email FROM usuarios LIMIT 25');
$resultado sqlite_fetch_all($consultaSQLITE_ASSOC);
foreach (
$resultado as $fila) {
    echo 
'Nombre: ' $fila['nombre'] . '  E-mail: ' $fila['email'];
}
?>

Example #2 Ejemplo orientado a objetos

<?php
$manejador_bd 
= new SQLiteDatabase('sqlitedb');

$consulta $manejador_bd->query('SELECT nombre, email FROM usuarios LIMIT 25'); // resultado almacenado (buffered)
$consulta $manejador_bd->unbufferedQuery('SELECT nombre, email FROM usuarios LIMIT 25'); // resultado no almacenado (unbuffered)

$resultado $consulta->fetchAll(SQLITE_ASSOC);
foreach (
$resultado as $fila) {
    echo 
'Nombre: ' $fila['nombre'] . '  E-mail: ' $fila['email'];
}
?>



add a note add a note User Contributed Notes
sqlite_fetch_array
saleh at sfsj dot net
10-May-2004 03:12
[Editor's note: to get short column names there's an undocumented PRAGMA setting. You can exec "PRAGMA short_column_names = ON" to force that behavior.]

I noticed that if you use Joins in SQL queries, the field name is messed up with the dot!
for example if you have this query:
SELECT n.*, m.nickname FROM news AS n, members AS m WHERE n.memberID = m.id;

now if you want to print_r the results returned using SQLITE_ASSOC type, the result array is like this :
array
(
  [n.memberID] => 2
  [n.title] => test title
  [m.nickname] => NeverMind
  [tablename.fieldname] => value
)

and I think it looks horriable to use the variable ,for example, $news['m.nickname'] I just don't like it!

so I've made a small function that will remove the table name (or its Alias) and will return the array after its index is cleaned
<?php
function CleanName($array)
{
  foreach (
$array as $key => $value) {
   
//if you want to keep the old element with its key remove the following line
     
unset($array[$key]);

  
//now we clean the key from the dot and tablename (alise) and set the new element
     
$key = substr($key, strpos($key, '.')+1);
     
$array[$key] = $value;
  }
  return
$array;
}
?>

sqlite_fetch_column_types> <sqlite_fetch_all
Last updated: Fri, 22 Aug 2008
 
 
show source | credits | sitemap | contact | advertising | mirror sites