Home >Backend Development >PHP Tutorial >Yii operates the database to dynamically obtain the table name, yii database_PHP tutorial

Yii operates the database to dynamically obtain the table name, yii database_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:55:121004browse

Yii operates the database to dynamically obtain the table name, yii database

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.

Articles you may be interested in:

  • How to create and use Model in Yii
  • PHP YII framework development tips for rules in models (models) Define validation rules
  • Example of using yii framework form model and submitting form data in array form
  • Yii database cache instance analysis
  • Yii framework upload image usage summary
  • How to enable fragment caching in Yii
  • Detailed explanation of attribute injection and method injection of component behavior in PHP's Yii framework
  • How to remove the behavior bound to a component in PHP's Yii framework
  • Explanation of the definition and binding methods of behaviors in PHP's Yii framework
  • Detailed explanation of how to use behavioral Behaviors in PHP's Yii framework
  • Interpretation of requests and responses in PHP's Yii framework Processing flow
  • Example tutorial on database configuration and SQL operation using PHP's Yii framework
  • YII dynamic model (dynamic table name) supports analysis

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1117087.htmlTechArticleYii operates the database to dynamically obtain the table name, yii database This article describes the example of Yii operating the database to dynamically obtain the table Name method. Share it with everyone for your reference, specifically...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn