Export Database to Excel or CSV File

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

exporttoxls

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’;
exit;
}

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

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

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

mysql_free_result($result);
?>

Filed Under: PHPProgramming

Tags:

About the Author: me : yeay its me arun

RSSComments (2)

Leave a Reply | Trackback URL

  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

Videos, Slideshows and Podcasts by Cincopa Wordpress Plugin