PHP PDO获取所有表 [英] PHP PDO fetch all tables
本文介绍了PHP PDO获取所有表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我知道通过标准的mysql调用我们可以做到mysql_list_tables
,但是使用PDO时是否有等效功能?如果是这样,这是否返回一个数组?谢谢!
So I know with a standard mysql call we can do mysql_list_tables
, however is there an equivalent while using PDO? If so, does this return an array? Thanks!
推荐答案
使用PDO::query()
执行查询:
SHOW TABLES;
如果获取关联数组,则列的名称为:
If you fetch an associative array, the name of the column will be:
Tables_in_databasename
注意:这将同时列出表和视图.如果您必须仅获取表,请使用此表:
Note: this will list both tables and views. If you must get only tables, use this instead:
SELECT
TABLE_NAME
FROM information_schema.TABLES
WHERE
TABLE_TYPE='BASE TABLE'
AND TABLE_SCHEMA='yourdatabasename';
这篇关于PHP PDO获取所有表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文