如何获取yii中的所有表名?
MysqL中的SQL查询是SHOW TABLES.
我试过了:
$sql = 'SHOW TABLES';
$tables = Yii::app()->db
->createCommand($sql)
->queryAll();
print_r($tables);
CDbCommand Failed to execute the sql statement:
CDbCommand Failed to prepare the sql statement:
sqlSTATE[HY000]: General error: 1 near "SHOW": Syntax error.
The sql statement executed was: SHOW TABLES
解决方法:
试试这个:
$connection = Yii::app()->db;//get connection
$dbSchema = $connection->schema;
//or $connection->getSchema();
$tables = $dbSchema->getTables();//returns array of tbl schema's
foreach($tables as $tbl)
{
echo $tbl->rawName, ':<br/>', implode(', ', $tbl->columnNames), '<br/>';
}
请参考:How to get all table and column names from database in Yii Framework
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。