我有以下一段代码,它在我的数据库中显示了我当前表名的列表,它工作正常。
Run Code Online (Sandbox Code Playgroud)<?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 />'; } ?>
您能像在 mysql 中那样显示表的列名列表吗?我尝试了无数次迭代,但都失败了。
只是为了记录,这是我使用的代码,感谢 esqew 的帮助:
<?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 />';
} ?>
Run Code Online (Sandbox Code Playgroud)
所有测试和工作
PRAGMA table_info(sqlite_master);
Run Code Online (Sandbox Code Playgroud)
要将其适合您的 PHP 实现:
<?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 />';
} ?>
Run Code Online (Sandbox Code Playgroud)