我有以下代码的工作版本,结果为can be seen here。
<?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 />';
}
?>
问题是我在这个数据库USERS
和ADMIN_LOGIN
中只有两个表,但我出现了sqlite_sequence
。有没有办法我只能显示表名而不是sqlite_sequence
?
答案 0 :(得分:5)
使用PHP检查表是否已命名为sqlite_sequence
,如果不是,则输出表的名称。
<?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)) {
if ($table['name'] != "sqlite_sequence") {
echo $table['name'] . ' <br />';
}
}
?>
答案 1 :(得分:2)
如何更改初始查询以忽略sqlite_sequence
作为name != 'sqlite_sequence
条件?
// Display all sqlite tables
$db = new SQLite3('data.db');
$sql = "SELECT name FROM sqlite_master WHERE type = 'table' AND name != 'sqlite_sequence';";
$tablesquery = $db->query($sql);
while ($table = $tablesquery->fetchArray(SQLITE3_ASSOC)) {
echo $table['name'] . ' <br />';
}
或者您可以使用sqlite*
NOT LIKE
前缀的表格
// Display all sqlite tables
$db = new SQLite3('data.db');
$sql = "SELECT name FROM sqlite_master WHERE type = 'table' AND name NOT LIKE 'sqlite%';";
$tablesquery = $db->query($sql);
while ($table = $tablesquery->fetchArray(SQLITE3_ASSOC)) {
echo $table['name'] . ' <br />';
}