Export MySQL to CSV using php
Export MySQL to CSV using php
You can export your MySQL database to csv 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'); ?>Export MySQL to CSV using php,
Incoming search terms:
- export mysql to excel using php (156)
- php mysql export to excel (49)
- export mysql table to excel using php (47)
- php export mysql to csv (36)
- php mysql to csv (30)
- export mysql to excel php script (27)
- export mysql database to excel using php (26)
- php mysql csv export script (25)
- php mysql export csv (25)
- mysql to csv php (23)
- php script to export mysql to csv (23)
- php export mysql to excel (23)
- export from mysql to excel php (21)
- mysql to excel using php (21)
- php export to excel tutorial (21)
- how to export mysql table to excel using php (21)
- php export mysql table as csv tutorial (20)
- php script to export mysql to excel (19)
- php mysql export to excel script (18)
- export mysql to excel (18)
- php mysql export excel (17)
- symfony2 export csv (17)
- symfony2 csv (17)
- Excel php mysql (16)
- export mysql to excel php (16)
- php mysql excel export (15)
- php mysql to excel (15)
- export mysql to csv php (14)
- export to excel using php (13)
- export mysql to excel script (13)
- php export to excel example (12)
- mysql export to excel (12)
- php export excel tutorial (11)
- symfony2 export to excel (11)
- php mysql csv export (10)
- jqgrid csv export (6)
- export csv in php (3)
- mysql to excel en symfony (2)
- perl export mysql to excel (2)
- download mysql data into excel button php ajax (2)
thank youuuuuuuuuuuuuuuuuuuu!!
it is not export an csv on android device
the best………………