Provides various official and user-released code examples. For code reference, you are welcome to exchange and learn the business. You need to add a table every month to deal with a large amount of data. The following is the source code for the dynamic creation of data table structures in thinkphp.
$ Table = 'activelog'. date ('ym ');
$ SQL = "CREATE TABLE IF NOT EXISTS '$ table '(
'Id' int (11) not null AUTO_INCREMENT,
'System' tinyint (4) not null comment 'xxxxxx ',
'Pfid' smallint (4) not null,
'Uid' int (11) not null,
.....
'Update _ time' timestamp not null default CURRENT_TIMESTAMP ON update CURRENT_TIMESTAMP,
Primary key ('id ')
) ENGINE = InnoDB default charset = utf8 COMMENT = 'Active statistics' AUTO_INCREMENT = 1 ;";
M ('','', 'db _ CONFIG_ACTIVE ')-> execute ($ SQL); // note that if you create a table here, do not set the first parameter, otherwise, the table information will be detected, but the table does not exist, resulting in an error.
Let's look at the details:
Thinkphp3.2 will enable data table field detection by default, in Model. class. php
View Source Code
// Whether to automatically check the field information of the data table
Protected $ autoCheckFields = true;
In the db method, there are 1409 lines of code:
If (! Empty ($ this-> name) & $ this-> autoCheckFields) $ this-> _ checkTableInfo ();
$ This-> name is set in the constructor, that is, the first parameter of M ('','', 'xxx. Parameter 3 is the database connection information.
I encountered this when writing business logic today. By the way, I hope it will help you.
You can also refer to my personal website: http://www.isbala.com/article/270.html
AD: truly free, domain name + VM + enterprise mailbox = 0 RMB