CSV export of a MySQL query using a PHP class. Full article and function source at: http://imelgrat.me/php/csv-exports-using-php-class
<?php | |
#Include the class. This class takes the results of a SQL query and outputs in the CSV (comma separated values) format. | |
require_once("iam_csvdump.php"); | |
# Set the parameters: SQL Query, hostname, databasename, dbuser and password | |
$dumpfile = new iam_csvdump; | |
# Call the CSV Dumping function and THAT'S IT!!!! A file named export.csv is sent to the user for download | |
$dumpfile->dump("SELECT * FROM `tablename`", "export", "csv", "mysql", "root", "", "localhost" ); | |
?> |
<?php | |
#Include the class. This class takes the results of a SQL query and outputs in the CSV (comma separated values) format. | |
require_once("iam_csvdump.php"); | |
# Set the parameters: SQL Query, hostname, databasename, dbuser and password | |
$dumpfile = new iam_csvdump; | |
# Call the CSV Dumping function with empty filenames and extension to send the query results to the browser as raw text | |
$dumpfile->dump("SELECT * FROM user", "", "", "mysql", "root", "", "localhost" ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment