PHP Velho Oeste 2024

sqlite_fetch_column_types

SQLiteDatabase::fetchColumnTypes

(PHP 5 < 5.4.0)

sqlite_fetch_column_types -- SQLiteDatabase::fetchColumnTypes Devuelve un array con los tipos de columna de una tabla en particular

Descripción

sqlite_fetch_column_types ( string $table_name , resource $dbhandle [, int $result_type = SQLITE_ASSOC ] ) : array

Estilo orientado a objetos (método):

public SQLiteDatabase::fetchColumnTypes ( string $table_name [, int $result_type = SQLITE_ASSOC ] ) : array

sqlite_fetch_column_types() devuelve un array con los tipos de datos de las columnas de la tabla especificada por table_name.

Parámetros

table_name

El nombre de la tabla a consultar.

dbhandle

El resucrso de Base de datos de SQLite; devuelto desde sqlite_open() cuando se usa procedimentalmente. Este parámetro no es necesario al usar elmétodo orientado a objetos.

result_type

El parámetro opcional result_type acepta una constante y determina cómo el array devuelto será indexado. Al utilizar SQLITE_ASSOC devolverá solamente índices asociativos (campos con nombre) mientras que SQLITE_NUM devolverá solamente índices numéricos (números ordinales de campos). SQLITE_ASSOC es el predeterminado para esta función.

Valores devueltos

Devuelve un array con los tipos de datos de las columnas; FALSE en caso de error.

Los nombre de las columnas devueltos por SQLITE_ASSOC y SQLITE_BOTH serán mayúsculas o no de acuerdo al valor de la opción de configuración sqlite.assoc_case.

Historial de cambios

Versión Descripción
5.1.0 Se añadió el parámetro result_type

Ejemplos

Ejemplo #1 Ejemplo prodecimental

<?php
$db 
sqlite_open('mysqlitedb');
sqlite_query($db'CREATE TABLE foo (bar varchar(10), arf text)');
$cols sqlite_fetch_column_types('foo'$dbSQLITE_ASSOC);

foreach (
$cols as $column => $type) {
    echo 
"Column: $column  Type: $type\n";
}
?>

Ejemplo #2 Ejemplo orientado a objetos

<?php
$db 
= new SQLiteDatabase('mysqlitedb');
$db->query('CREATE TABLE foo (bar varchar(10), arf text)');
$cols $db->fetchColumnTypes('foo'SQLITE_ASSOC);

foreach (
$cols as $column => $type) {
    echo 
"Columna: $column  Tipo: $type\n";
}
?>

El resultado del ejemplo sería:

Columna: bar  Tipo: VARCHAR
Columna: arf  Tipo: TEXT

add a note add a note

User Contributed Notes 3 notes

up
1
Anonymous
19 years ago
The problem with the permanently locked database file when using this function still seems to exist in PHP 5.0.3 (tested on win32).

However, you can get all the information you need about the fields of a table by using this query:

PRAGMA table_info(name_of_your_table);
up
-1
enthusiast
19 years ago
If I (OO version) try to add the contant SQLITE_ASSOC, (exactly as listed in the above example) it generates the following error:

SQLiteDatabase::fetchColumnTypes() expects exactly 1 parameter, 2 given in C:\....

If I remove it completely, it returns the associative array I expected.
up
-1
hugo_pl at users dot sourceforge dot net
19 years ago
This function, and the OO version, is bugged in PHP <= 5.0.1, locking the database until you restart the webserver.

http://bugs.php.net/bug.php?id=29476
To Top