添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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.

Just for the record this is the code I used thanks to esqew for the help:

<?php // Display all sqlite column names for chosen table
    $db = new SQLite3('data.db');
    $tablesquery = $db->query("PRAGMA table_info(USERS)");
    while ($table = $tablesquery->fetchArray(SQLITE3_ASSOC)) {
        echo $table['name'] . '<br />';

All tested and working

<?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 />';
                @FullDecent OP was asking about column names for the sqlite_master table. Would this not be the expected output?
– esqew
                May 10, 2018 at 16:00

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

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.