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.
sqlite_fetch_column_types
SQLiteDatabase::fetchColumnTypes
(PHP 5 < 5.4.0)
sqlite_fetch_column_types -- SQLiteDatabase::fetchColumnTypes — Restituisce un array con il tipo delle colonne di una tabella
Descrizione
$table_name
, resource $dbhandle
[, int $result_type = SQLITE_ASSOC
] )Stile orientato agli oggetti (metodo):
$table_name
[, int $result_type = SQLITE_ASSOC
] )
sqlite_fetch_column_types() restituisce un array
con il tipo di dato delle colonne della tabella indicata da table_name.
Elenco dei parametri
-
table_name -
Il nome della tabella da interrogare.
-
dbhandle -
Risorsa Database SQLite; restituita da sqlite_open() quando usato in modo procedurale. Questo parametro non è richiesto nel metodo ad oggetti.
-
result_type -
Il parametro opzionale
result_typeaccetta una costante e determina come l'array restituito sarà indicizzato. UtilizzandoSQLITE_ASSOCsaranno restituito solo indici associativi (nomi dei campi) mentreSQLITE_NUMrestituirà solo gli indici numerici (numeri di campo ordinari).SQLITE_ASSOCè il valore di default per questa funzione.
Valori restituiti
Restituisce un array con i tipi di dati delle colonne, oppure FALSE in caso di errore.
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
.
Log delle modifiche
| Versione | Descrizione |
|---|---|
| 5.1.0 | Aggiunto result_type |
Esempi
Example #1 Esempio procedurale
<?php
$db = sqlite_open('mysqlitedb');
sqlite_query($db, 'CREATE TABLE foo (bar varchar(10), arf text)');
$cols = sqlite_fetch_column_types('foo', $db, SQLITE_ASSOC);
foreach ($cols as $column => $type) {
echo "Colonna: $column Tipo: $type\n";
}
?>
Example #2 Esempio ad oggetti
<?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 "Colonna: $column Tipo: $type\n";
}
?>
Il precedente esempio visualizzerà:
Colonna: bar Tipo: VARCHAR Colonna: arf Tipo: TEXT
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);
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
