5

I have the following piece of code which displays a list of my current table names in my database which works fine.

<?php // Display all sqlite tables
    $db = new SQLite3('data.db');
    $tablesquery = $db->query("SELECT name FROM sqlite_master WHERE type='table';");

    while ($table = $tablesquery->fetchArray(SQLITE3_ASSOC)) {
        echo $table['name'] . '<br />';
} ?>

Can you display the list of column names for a table like you can do in mysql? I have tried numerous iterations and all have failed.

0

2 Answers 2

3

Refer to SQLite.org - PRAGMA Statements:

PRAGMA table_info(sqlite_master);

To fit it into your PHP implementation:

<?php // Display all sqlite tables
    $db = new SQLite3('data.db');
    $tablesquery = $db->query("PRAGMA table_info(sqlite_master);");

    while ($table = $tablesquery->fetchArray(SQLITE3_ASSOC)) {
        echo $table['name'] . '<br />';
} ?>
Sign up to request clarification or add additional context in comments.

2 Comments

Useless, this is table names, not column names.
@FullDecent OP was asking about column names for the sqlite_master table. Would this not be the expected output?
0

Try this sqlite table schema parser, I implemented the sqlite table parser for parsing the table definitions in PHP.

https://github.com/maghead/sqlite-parser

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.