Can I generate a CSV file from phpMyAdmin based on a MySQL query?
For example, let's say I queried a table to return results for the word "image". Could I then produce a CSV with all of the records containing the word "image"?
use the command insert...select to create a "result" table. The ideal scenario whould be to automatically create the fields of this result table, but this is not possible in mysql. create an ODBC connection to the database. use access or excel to extract the data and then save or process in the way you want.
On the PHPMyAdmin SQL section, you will put your procedural query and save this query as a bookmark which you will see on the lower side of the page which I indicate with a red arrow. It's a good idea but you can also try to save your query on PHP function and run them using a function call.
In PhpMyAdmin, go into the SQL tab and enter your query in there. Hit go, then click Export
at the bottom of your results. You can select to export as a CSV.
In case you're interested, here's how to do it via SQL without PMA: How to output MySQL query results in CSV format?
You may be able to use the SELECT ... INTO OUTFILE... functionality. Although this will place the CSV file on the server. That's a long page, because it's the page for the whole "Select" syntax, but the basics are below:
SELECT col1,col2,col3 INTO OUTFILE '/tmp/result.txt'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM MyTable;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With