| |||||||||||
| |||||||||||
Saving a MySQL query results to your local disc for Excel
Do you want to run a database query on a remote server and save the results into a text file on your LOCAL disc - i.e. the disc of the computer at which you're seated and not the disc of the server that's in a remote location?
It's not as easy as you think it should be. Because of the security risks involved, you cannot save to LOCAL OUTFILE from a SELECT in MySQL, even though you can read from LOCAL INFILE in a LOAD. Reading in known data is OK, but saving what could be malicious or confidential information away from the server is quite a different kettle of fish. Solution? One possibility is to wrap your query in a web page, and allow your browser's facilities to store the result set locally. In other words, to put up a form and have the user enter his query in that. When submitted, the user's browser deals with the security issues of saving the data locally using the security preferences already set up by the user for his browser.. I've written a sample script to demonstrate the saving of a query result to a local .csv file. You could change the comma to a tab separator for your own use and that way you'll get a page that save a databases to your local system suitable for import to spreadsheets such as Excel. Run the script here View the source here Other common questions on MySQL answered here UPDATE - Summer '07. See also additional comments about the header() function and changes needed to the original script for new PHP versions!. Thank you. (written 2006-01-29 06:12:41) Associated topics are indexed under H113 - Using MySQL Databases in PHP PagesS157 - More MySQL Commands
Some other Articles
Looking for Python staffLoosing breath with Gerald Remember to process blank lines DWIM and AWWO Saving a MySQL query results to your local disc for Excel What to do with milk Short Linux and Perl courses for small groups Woman screaming at me Learning to program in Perl or PHP Why run two different web servers 1689 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34 at 50 posts per pageThis is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price. Link to Ezine home page (for reading). Link to Blogging home page (to add comments). |
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 707126 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho | |||||||||||