I need to import and export mysql databases using php code, as a part of backing up and restoring database in the admin panel of the web site.
Someone help me out.
Need it soon.
lots of ways to do it... one way I've done it when dealing with large sql files is open a pipe to mysqladmin and dump the SQL into it.
public function __construct()
$this->descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("file", "/tmp/error-output.txt", "a")
public function connect($command)
$this->process = proc_open($command,
public function send($message)
public function read()
$response .= fgets($this->pipes, 1024);
public function close()
public function __destruct()
/********** usage *****/
$process =& new Process;
$process->connect('mysqldump -u testuser -p --no-data testdb');
$response = $process->read();
this works... however the process class is "funny" as I cannot seem to read or wite to a proces after the initial read/writes. Still... works for the task at hand (you could replace the command with a mysql command... i.e. 'mysql -u user -p db < sqlfile.sql' and write your password to it. if you don't have pcntl, you can use popen (www.php.net/popen).
Also, in the most barebones of ways, you could read from the sql file line by line and pass it to mysql_query.
Thank you for the advice,
I tried it but I need the code that runs in the windows platform. Unix specific functions such as proc_open() could not be executed.
So please help me out.
Moved to a more appropriate forum. See Where should I post my thread? for details
or better yet, call mysql's mysqldump to have mysql do all the work...
a single line of php code will backup the stuff...
This topic is now closed. New replies are no longer allowed.