Home >Backend Development >PHP Tutorial >Thinkphp connection table query and data export method

Thinkphp connection table query and data export method

墨辰丷
墨辰丷Original
2018-06-01 09:13:451615browse

This article mainly introduces the ThinkPHP connection table query and data export methods, and analyzes the operation skills and related precautions of thinkPHP connection table query in the form of examples. Friends in need can refer to this

Today's experiment The recruitment work of the laboratory is about to begin. We are linked to Hangzhou Dian OJ through the laboratory website. Freshmen will submit their Hangzhou Dian usernames on the laboratory website, and the website will crawl to Hangzhou Dian OJ for data capture. Save to laboratory database.

What I have to do now is to jointly export the new table and the new OJ data table. The laboratory website is developed using the thinkphp framework. So based on previous work experience. The problem was solved quickly.

Now share it with you.

Thinkphp's extension classes are placed under the ORG directory. When viewing the connected table by calling the import() function, you can use the advanced view mode or not.

//不用高级视图模式。
//两张表,userinfo和oj_data
//导出学生信息
$user = $userinfo->table('lab_userinfo,lab_oj_data')
->field(
'lab_userinfo.userid,
lab_userinfo.truename,
lab_userinfo.year,
lab_userinfo.sex,
lab_userinfo.subject,
lab_userinfo.email,
lab_userinfo.date,
lab_oj_data.username as username,
lab_oj_data.solved as solved,
lab_oj_data.Submit as Submit,
lab_oj_data.AC as AC')
->where('lab_userinfo.userid=lab_oj_data.userid and pass=0')->order('lab_oj_data.solved desc')
->select();

It should be noted. If the data table prefix is ​​set in the configuration of the thinkphp framework, be sure to note that except for model calls, which will automatically add the prefix, everything else must be added manually.

Anyone who has studied SQL knows that sql statements allow the use of aliases for tables.

So when we declare the table using table(), we can use an alias

table('lab_userinfo userinfo,lab_oj_data data');

This is different from the SQL statement. AS is not used when aliasing a table.

Then there is the issue of data export. You can refer to the previous article "Example of class library usage for exporting excel data in PHP"

Summary: The above is the entire article Content, I hope it will be helpful to everyone's study.

Related recommendations:

phpExport file compression package ZipArchive

##PHP memory overflow, command Understanding the two execution methods of row and web services

##Detailed explanation of the usage of class library for exporting excel data in PHP


The above is the detailed content of Thinkphp connection table query and data export method. For more information, please follow other related articles on the PHP Chinese website!

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