PHP Velho Oeste 2024

sqlite_fetch_column_types

SQLiteDatabase::fetchColumnTypes

(PHP 5 < 5.4.0)

sqlite_fetch_column_types -- SQLiteDatabase::fetchColumnTypes Liefert ein Array mit den Spaltentypen einer bestimmten Tabelle

Beschreibung

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

Objektorientierter Stil (Methode):

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

sqlite_fetch_column_types() liefert ein Array mit den Datentypen aller Spalten in der angegebenen Tabelle table_name.

Parameter-Liste

table_name

Der abzufragende Tabellenname.

dbhandle

Die Ressource der SQLite-Datenbank, die bei prozeduraler Benutzung von sqlite_open() zurückgegeben wurden. Der Parameter wird bei der objektorientierten Notation nicht benötigt.

result_type

Der optionale Parameter result_type akzeptiert eine Konstante und bestimmt, wie die Rückgabeliste indiziert wird. Mit SQLITE_ASSOC werden nur assoziative Indices (Namensfelder) und mit SQLITE_NUM werden nur numerische Indices (geordnete Feldnummern) gesetzt. SQLITE_ASSOC ist Standard.

Rückgabewerte

Liefert ein Array der Datentypen aller Spalten oder FALSE im Fehlerfall.

Die Groß- und Kleinschreibung der Spaltennamen, die von SQLITE_ASSOC und SQLITE_BOTH zurückgegeben werden, wird entsprechend der Konfigurationsdirektive sqlite.assoc_case geändert.

Changelog

Version Beschreibung
5.1.0 result_type hinzugefügt

Beispiele

Beispiel #1 Prozedurales Beispiel

<?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 
"Spalte: $column  Typ: $type";
}
?>

Beispiel #2 Objektorientiertes Beispiel

<?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 
"Spalte: $column  Typ: $type";
}
?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

Spalte: bar  Typ: VARCHAR
Spalte: arf  Typ: 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