如何在Laravel 5.1中获取数据库中的表列表 [英] How to fetch the tables list in database in Laravel 5.1
本文介绍了如何在Laravel 5.1中获取数据库中的表列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要列出数据库
中的表
,我找到了
I need to list out the tables
in database
, I found the query for
SHOW TABLES LIKE 'merTrans%'
获取表,但是如何使用 foreach
在 Laravel 5.1
中获取表名?
get the tables but how could I use the foreach
to get the table names in Laravel 5.1
?
推荐答案
要列出数据库中的表,您可以
To list out the tables in database you can do
$tables = DB::select('SHOW TABLES');
foreach($tables as $table)
{
echo $table->Tables_in_db_name;
}
您必须将db_name更改为数据库的名称.
You'll have to change the db_name to the name of your database.
用于类似情况
foreach ($tables as $table) {
foreach ($table as $key => $value)
echo $value;
}
这篇关于如何在Laravel 5.1中获取数据库中的表列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文