Home >Backend Development >PHP Tutorial >Yii operates the database to dynamically obtain the table name, yii database_PHP tutorial
This article describes the example of Yii operating the database to dynamically obtain the table name. Share it with everyone for your reference, the details are as follows:
yii obtains the table name in a certain library, and the library is not sure how many tables there are. At this time, it is impossible to generate files based on the table according to gii. Here is a way to solve it.
$sqls = "show tables"; $datebase = YII::app()->db_order->createCommand($sqls)->queryAll(); //获取表名
Here $datebase is the name of all tables. I currently have 4 libraries. A website shares these 4 libraries and sometimes switches back and forth. db_order is one of the four libraries defined in main.php. The other libraries are db db_order db_query db_log. Then you can get the data from all tables in this library. Instead of generating it.
This method is generally used on game platforms. For example, I currently have a library specifically to store orders. So the library is set up as db_order. At this time, I need to get all the recharge records (orders) of a certain user.
Readers who are interested in more Yii-related content can check out the special topics on this site: "Introduction to Yii Framework and Summary of Common Techniques", "Summary of Excellent PHP Development Framework", "Basic Tutorial for Getting Started with Smarty Templates", "php Date and Time" Usage Summary", "php object-oriented programming introductory tutorial", "php string (string) usage summary", "php mysql database operation introductory tutorial" and "php common database operation skills summary"
I hope this article will be helpful to everyone’s PHP program design based on the Yii framework.