Forum Moderators: coopster
<?php
ob_start();
$username = "";
$password = "";
$hostname = "localhost";
$sConnString = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
//create a connection object
$connection = mysql_select_db("dbname",$sConnString)
or die("Could not select DB");
$command = "mysqldump --add-drop-table --host=localhost --user='' --password='' dbname";
system($command);
$dump = ob_get_contents();
ob_end_clean();
//The database dump now exists in the $dump variable... write it to a file using...
$fp = fopen("dump.sql", "w");
fputs($fp, $dump);
fclose($fp);
?>
By the way, the --user='' bits are single quotes - I don't think this shows up on the post very well...might look like double quotes.
Thanks
That doesn't make sense as dbname is the database name...
However when I put this into the PHP script, nothing happens, so I'm wondering if there's something with my path format or if this isn't picked up by the system() function:
$command = "\Program Files\MySQL\MySQL Server 4.1\bin\mysqldump --add-drop-table --host=$hostname --databases dbname > tester.sql";
system($command);
Thanks