MySQL method to export data to excel _ MySQL

Source: Internet
Author: User
MySQL method to export data to excel bitsCN.com
It is very easy for MySQL to export data to an excel file. execute a command like this: select * from a table into outfile 'd:/file name .xls; the preceding command is executed on the server, it is exported to server D: Disk. if it is executed in the client command line mode, it is exported to client D: Disk. if it is executed in the client through POST mode, it is exported to server D: disk. The premise of successful import is that you have the login permission, select permission, and file permission. if you do not have the file permission, you will not be able to execute select .... into outfile and load data infile ..... As for adding a button, click the prompt to save it as an excel file. I think you may be referring to it on the webpage? On the web page, MySQL operations are generally blocked, and MySQL operations are generally performed through the server scripting language (PHP, JSP, ASP, and so on, the following uses PHP and JavaScript as examples to save the database query results as xls methods (I have practiced both methods, which is feasible): 1.PHP method: call header () function, the parameter is as follows: header ("content-type: application/msexcel"); header ("content-disposition: filename=file001.xls "); these two functions are placed in the PHP file before performing database query operations. Generally, after the database query operation is completed, the query results can be displayed to the client through functions such as echo () and printf (). If the preceding two rows are added before the database operation is executed, the client will not display the results, but a dialog box is displayed for download and save as xls. the path and file name can be freely selected. Button Or you can place the link on the 1st page and point it to the 2nd page. the 1st page is used to display the result to the client, and the 2nd page (php file) is placed on the above two lines, then write the code to connect to the database and execute the same query operation as page 1st. In this way, you click this link on the 1st page to pop up a dialog box for download and save as xls. the saved content is the query result you see on the 1st page. the saved format is xls, after saving, you can open it in Excel for operations. PHP is a server-side script. In fact, the same data result is transmitted twice from the server to the client using the above method. it is used for display for the first time, and the second is used to package it into an xls file for download. 2. JavaScript method: first, go toSome define a JS function:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.