获取我的数据库中所有表的名称 [英] Get the name of all the tables on my database

查看:50
本文介绍了获取我的数据库中所有表的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取数据库中存在的所有表的名称.我像我的 ORM 一样使用 Propel.其实我一直在尝试这个表格.

$dbmap = \Propel::getDatabaseMap('data');$tablastmp = $dbmap->getTables();$tablas = array();foreach ($tablastmp 作为 $tablatmp) {$tablas[] = $tablatmp->getName();}echo '

';打印_r($tablas);echo '</pre>';死();

但这会返回一个空数组.

数组();

我需要返回类似的东西:

array( [0] => 'clients', [1] => 'workers' );

请人帮忙.我已经尝试了几天.

解决方案

实际上,您可能不会使用 Propel 来获取这些信息,因为 Propel 只会在实际使用表时加载表映射信息.

原始架构文件在构建阶段使用(运行propel_gen om"等).Propel 的运行时部分从不查看 Schema 文件,因此无法查询它本身.

您的问题的答案是查看数据库,例如MySQL 查询以列出数据库中的表:显示 [完整] 表格 [{来自 |IN} db_name][喜欢'模式' |WHERE expr]

I need get the name of all the tables that exist on my database. I am usin Propel like my ORM. Actully i have been trying on this form.

$dbmap = \Propel::getDatabaseMap('data');
    $tablastmp = $dbmap->getTables();
    $tablas = array();
    foreach ($tablastmp as $tablatmp) {
        $tablas[] = $tablatmp->getName();
    }
    echo '<pre>';
    print_r($tablas);
    echo '</pre>';
    die();

but this return an array that is empty.

array();

And I need that return something like that:

array( [0] => 'clients', [1] => 'workers' );

Please someone help. I have been trying that for a few days.

解决方案

Actually, you probably wouldn't use Propel to get this information as Propel only loads the table map information when the table is actually used.

The original Schema file is used during the build phase (running 'propel_gen om' etc). The runtime part of Propel never looks at the Schema file, so there is no way to query it per se.

The answer to your question is to look at the database, e.g. the MySQL query to list the tables in a database: SHOW [FULL] TABLES [{FROM | IN} db_name] [LIKE 'pattern' | WHERE expr]

这篇关于获取我的数据库中所有表的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆