retrieve列名来自sqlite3数据库,带有php

问题描述 投票:0回答:2

我有以下代码,其中显示了我的数据库中我当前表名的列表,该列表正常。

<?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中一样显示表格的列名列表吗?我尝试了许多迭代,都失败了。

php sqlite
2个回答
3
投票
sqlite.org-pragma语句:

PRAGMA table_info(sqlite_master);

将其适合您的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 />'; } ?>



0
投票

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

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.