Get the name of all the tables on my database

↘锁芯ラ 提交于 2019-12-13 14:32:31

问题


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.


回答1:


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]




回答2:


This might help you (hopefully)

$em = $this->getDoctrine()->getManager();
foreach ($em->getMetadataFactory()->getAllMetadata() as $md) {
    var_dump($md->getName()); // dump the full class names
    var_dump($md->getTableName()); // dump the table names
}


来源:https://stackoverflow.com/questions/22382027/get-the-name-of-all-the-tables-on-my-database

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!