You can export your MySQL database to .csv file format (Microsoft Excel file) easily using php.
This tutorial require 1 PHP file and 1 table of mySQL database.
1. exportcsv.php
2. The table is with 2 fields: id(auto_increment), name(varchar, 50) and put some records about 20 – 30 records into this table. (directly by phpMyAdmin)
The exportcsv.php file looks like this :-
< ?php
// Connect database
$database="mydb";
$table="mytablename";
mysql_connect("localhost","","");
mysql_select_db("mydb");
$result=mysql_query("select * from $table");
$out = '';
// Get all fields names in table "mytablename" in database "mydb".
$fields = mysql_list_fields(mydb,$table);
// Count the table fields and put the value into $columns.
$columns = mysql_num_fields($fields);
// Put the name of all fields to $out.
for ($i = 0; $i < $columns; $i++) {
$l=mysql_field_name($fields, $i);
$out .= '"'.$l.'",';
}
$out .="\n";
// Add all values in the table to $out.
while ($l = mysql_fetch_array($result)) {
for ($i = 0; $i < $columns; $i++) {
$out .='"'.$l["$i"].'",';
}
$out .="\n";
}
// Open file export.csv.
$f = fopen ('export.csv','w');
// Put all values from $out to export.csv.
fputs($f, $out);
fclose($f);
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename="export.csv"');
readfile('export.csv');
?>
Incoming search terms:
- export mysql to excel using php (102)
- php export mysql to csv (26)
- export mysql table to excel using php (24)
- php script to export mysql to csv (19)
- php mysql export csv (18)
- php mysql csv export script (17)
- mysql to csv php (16)
- export mysql to excel php script (15)
- export mysql database to excel using php (14)
- Excel php mysql (13)
- php mysql to csv (13)
- mysql to excel using php (12)
- php mysql to excel (11)
- export mysql to excel script (10)
- export to excel using php (10)
- php mysql export to excel script (10)
- symfony2 csv (10)
- export mysql to excel (9)
- how to export mysql table to excel using php (9)
- php script to export mysql to excel (9)
- export mysql to csv php (8)
- export mysql to csv using php (8)
- how to export my sql result to microsoft excel 2010 using php (8)
- how to export mysql to excel using php (8)
- mysql export to excel (8)
- mysql to csv using php (8)
- php export mysql to excel (8)
- php mysql export to excel (8)
- php script export into excel (8)
- symfony2 csv export (8)
- export csv file php (7)
- export mysql to excel php (7)
- export mysql using php (7)
- exportMysqlToCsv php (7)
- jquery mysql export (7)
- mysql to excel php (7)
- ajax export to csv (6)
- exporting mysql data to excel using php (6)
- how to export mysql database to excel using php (6)
- MYSQL EXPORT TO EXCEL CSV (6)
You will also be interested in ,
- Mysql backup via cron using php and email the file
- Set xampp:- Apache Mysql Filezilla Mercury Tomcat as a windows service and get xampp to start automatically on boot up
- Display mysql table using for loop in php
- Search null value or fields in mysql
- Find the sum of multiple fields inside a table in mysql
- Count distinct records or values and display it using mysql and php
- Fix Too many connections mysql_connect
- Simple Mysql table with AUTO_INCREMENT attribute
- Simple Visitor Counter Using php
- Enabling curl on XAMPP for Windows

thank youuuuuuuuuuuuuuuuuuuu!!