Here I want to export the database into .sql format.I tried SELECT * INTO OUTFILE --- FROM --- command but it returns only records not whole structure of table. The code is
<?php
//include("db.php");
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db('ganga_hms');
$table_name = "accountant";
$backup_file = "C:/xampp/htdocs/FinalHMS/accountant.sql";
$sql = "SELECT * INTO OUTFILE '$backup_file' FROM $table_name";
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not take data backup: ' . mysql_error());
}
echo "Backedup data successfully\n";
mysql_close($conn);
?>
However I want to export table with its structure. And also suggest me that how to export the whole database using php.
To dump database you need "mysqldump" tool, but if do not have this tool on server and can not install it, you'll need a complex script that runs on all of your tables and gathers table structure and data like this: http://davidwalsh.name/backup-mysql-database-php