我有一个Laravel项目,我有一个sqlite数据库。我想在php artisan tinker
中查看数据库中的所有表。
我已尝试过此$tables = DB::select('SHOW TABLES');
,但会引发此错误Illuminate\Database\QueryException with message 'SQLSTATE[HY000]: General error: 1 near "SHOW": syntax error (SQL: SHOW TABLES)'
答案 0 :(得分:6)
以下是答案,可在此处找到https://www.sqlite.org/faq.html#q7
DB::select("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;")
感谢Laracasts上的@GwynBleidd找到答案。
答案 1 :(得分:0)
我知道这是一个老问题,但是我一直在寻找这个问题,根据Laravel语法,如果有人需要,找到了一个不同的解决方案,这里是:
DB::table('sqlite_master')->select('name')->where('type', 'table')->orderBy('name')->get()
通过这种方式,您可以执行查询搜索,或者如果需要,可以返回带有表名列表的Collection数组。
$this->DB
->table('sqlite_master')
->select('name')
->where('type', 'table')
->orderBy('name')
->get()
->pluck('name');