PHP Velho Oeste 2024

sqlite_fetch_column_types

SQLiteDatabase::fetchColumnTypes

(PHP 5 < 5.4.0)

sqlite_fetch_column_types -- SQLiteDatabase::fetchColumnTypes 特定のテーブルからカラム型の配列を返す

説明

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

オブジェクト指向型 (メソッド):

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

sqlite_fetch_column_types() は、 指定されたテーブル table_name からカラムのデータ型の配列を返します。

パラメータ

table_name

問い合わせるテーブル名

dbhandle

SQLite データベースリソース。手続きに従って、 sqlite_open() から返されます。 このパラメータは、 オブジェクト指向言語型メソッドを使用する場合は不要です。

result_type

オプションパラメータ result_type は定数を受け付け、 返される配列をどの様にインデックス付けするかを決定します。 SQLITE_ASSOC を使用すると連想インデックス (名前付けられたフィールド) のみを返し、 SQLITE_NUM の場合は数値インデックス (順序を表すフィールド番号) のみを返します。 SQLITE_ASSOC がこの関数のデフォルトです。

返り値

カラムのデータ型の配列を返します。エラー時は FALSE を返します。

SQLITE_ASSOC および SQLITE_BOTH で 返されるカラム名は、設定オプション sqlite.assoc_case の値に基づき、 大文字小文字が変換されます。

変更履歴

バージョン 説明
5.1.0 result_type が追加されました。

例1 手続き型言語スタイルでの例

<?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";
}
?>

例2 オブジェクト指向言語型スタイルでの例

<?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 
"Column: $column  Type: $type\n";
}
?>

上の例の出力は以下となります。

Column: bar  Type: VARCHAR
Column: arf  Type: 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