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 — Belli bir tablodaki sütun türlerini bir dizi içinde döndürür
Açıklama
$tablo_adı
, resource $db
[, int $sonuç_türü
] )Nesne yönelimli kullanım
$tablo_adı
[, int $sonuç_türü
] )
tablo_adı ile belirtilen tablodaki sütun türlerini
bir dizi içinde döndürür.
Değiştirgeler
-
tablo_adı -
Sorgulanacak tablonun ismi.
-
db -
SQLite Veritabanı özkaynağı. Yordamsal kullanımda sqlite_open() işlevi tarafından döndürülür. Nesne yönelimli kullanımda bu değiştirgeye gerek yoktur.
-
sonuç_türü -
İsteğe bağlı bu değiştirgede döndürülen dizinin nasıl oluşturulacağını belirleyen bir sabit belirtilir.
SQLITE_ASSOCbelirtilirse alanların isimleri indis olarak kullanılır.SQLITE_NUMbelirtilirse alanların sıra numaraları indis olarak kullanılır.SQLITE_BOTHiçin ise hem isimli hem de sayısal indisli bir dizi döner.SQLITE_BOTHbu işlev için öntanımlı değerdir.
Dönen Değerler
Bir hata durumunda FALSE yoksa sütun türlerini bir dizi içinde döndürür.
SQLITE_ASSOC ve
SQLITE_BOTH sabitleri kullanılarak döndürülen sütun
isimlerinin harf büyüklükleri
sqlite.assoc_case php.ini yapılandırma yönergesinin değerine uygun
olarak döndürülür.
Sürüm Bilgisi
| Sürüm: | Açıklama |
|---|---|
| 5.1.0 | sonuç_türü eklendi. |
Örnekler
Örnek 1 - Yordamsal kullanım örneği
<?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 "Sütun ismi: $column Türü: $type";
}
?>
Örnek 2 - Nesne yönelimli kullanım örneği
<?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 "Sütun ismi: $column Türü: $type";
}
?>
Yukarıdaki örneğin çıktısı:
Sütun ismi: bar Türü: VARCHAR Sütun ismi: arf Türü: 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
