PHP Velho Oeste 2024

sqlite_fetch_column_types

SQLiteDatabase->fetchColumnTypes

(PHP 5 < 5.4.0)

sqlite_fetch_column_types -- SQLiteDatabase->fetchColumnTypesBelli bir tablodaki sütun türlerini bir dizi içinde döndürür

Açıklama

sqlite_fetch_column_types ( string $tablo_adı , resource $db [, int $sonuç_türü ] ) : array

Nesne yönelimli kullanım

fetchColumnTypes ( string $tablo_adı [, int $sonuç_türü ] ) : array

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_ASSOC belirtilirse alanların isimleri indis olarak kullanılır. SQLITE_NUM belirtilirse alanların sıra numaraları indis olarak kullanılır. SQLITE_BOTH için ise hem isimli hem de sayısal indisli bir dizi döner. SQLITE_BOTH bu 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'$dbSQLITE_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

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