Kees Nuyt wrote:
>
> On Tue, 15 Jan 2008 11:33:06 -0800 (PST), "kamil.szot"
> <[EMAIL PROTECTED]> wrote:
>>With 2 (and probably 3) you will not be able to retrieve metadata (for
>>example column names) for empty table.
>>The only way of getting column names in PDO is executing "SELECT * FROM
>>table" query and then retrieving metadata using columnCount() and
>>getColumnMeta() methods of PDOStatement object returned by PDO->query()
>>method. But in case of sqlite: (meaning sqlite3) databases getColumnMeta()
>>returns nothing if result set is empty. In case sqlite2: driver
>>getColumnMeta() always throws exception.
>>
>>So if you will be needing to inspect your tables at runtime then I'm
>>recommending first solution.
>>
>>If anyone knows how to get field names of a table from sqlite3 database in
>>PHP please share your knowledge with the world. :-)
>
> There's a PRAGMA for that purpose.
>
> $sql = "PRAGMA table_info('tablename')";
> $res = $this->query($sql);
>
> Example result set:
> cid name type notnull dflt_value pk
> 0 jobid INTEGER 99 1
> 1 TSN CHAR(4) 0 0
> 2 jobprio INTEGER 0 9 0
> 3 status CHAR(1) 0 'W' 0
> 4 userid VARCHAR(8) 99 0
> etc.
>
> The columns of this resultset have metadata, just like a normal resultset.
>
> Tested with:
> php, php_pdo.dll, php_pdo_sqlite_external.dll v5.2.5.5 (2007-11-08,
> Windows),
> sqlite3.dll v3.5.4 (2007-12-14)
>
Thanks man! You made my day!
To no ones surprise it also works under Linux PHP 5.2.0.8 and libqlite3
3.3.8
--
View this message in context:
http://www.nabble.com/-Linux-%2B-PHP--Recommended-way-to-access-SQLite--tp14244097p14881348.html
Sent from the SQLite mailing list archive at Nabble.com.
-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------