Thinkphp table connection query and data export method example, thinkphp data export
This document describes how to connect to a table and export data using Thinkphp. We will share this with you for your reference. The details are as follows:
Today, the lab is about to recruit new students. We associate them with hangdian OJ through the lab website. Freshmen submit their hangdian user names on the lab website, the website crawls data on hangdian OJ and stores the data in the laboratory database.
Now I want to export the new table and the new OJ table. The lab website is developed using the thinkphp framework. Therefore, based on previous work experience. The problem was quickly solved.
Now let's share with you.
The extension classes of thinkphp are all placed under the ORG directory. You can use the advanced attempt mode or not to view the connection table through the import () function call.
// You do not need the advanced view mode. // Two tables, userinfo and oj_data // export Student Information $ user = $ userinfo-> table ('lab _ userinfo, lab_oj_data ')-> field ('lab _ userinfo. userid, role, lab_userinfo.year, lab_userinfo.sex, role, lab_userinfo.email, lab_userinfo.date, region as username, region as solved, region as Submit, region as AC')-> where ('lab _ userinfo. userid = lab_oj_data.userid and pass = 0')-> order ('lab _ oj_data.solved desc ')-> select ();
Note that. If the data table prefix is set in the thinkphp framework configuration, note that the prefix is automatically added in addition to the model call.
All those who have learned SQL know that SQL statements allow aliases of tables.
So we can use aliases when using tables declared in table ().
table('lab_userinfo userinfo,lab_oj_data data');
Unlike SQL statements, the alias for a table is not used.
For more information about data export, see the previous article "examples of using PHP to export excel Data class libraries".