Export Database to Excel or CSV File

The below code help you to export data from database to csv file


To export a complete database, you should invoke all the tables via below code and apply the above code
$dbname = ‘mysql_dbname’;

if (!mysql_connect(‘mysql_host’, ‘mysql_user’, ‘mysql_password’)) {
echo ‘Could not connect to mysql’;

$sql = “SHOW TABLES FROM $dbname”;
$result = mysql_query($sql);

if (!$result) {
echo “DB Error, could not list tables\n”;
echo ‘MySQL Error: ‘ . mysql_error();

while ($row = mysql_fetch_row($result)) {
echo “Table: {$row[0]}\n”;



me : yeay its me arun

Tagged with: , , , , ,
2 comments on “Export Database to Excel or CSV File
  1. Habeeb says:

    This script is for exporting a database table. But can you provide a script to export complete database?

  2. R Arun Raj says:

    answer is in the post

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.