Page 1 of 1

Possible to run mysqldump with mysql_query?

Posted: Wed Jun 07, 2006 12:25 am
by gnel2000
Hi there,

I'm trying to backup database with mysql dump.
But thats is only can be done thru the browser because of some restriction problem.

So what i did was trying to run the mysqldump with normal mysql_query, but seem like it doesn't work.

Is there any way to make it work?

Code: Select all

<?php
  @ $db = mysql_connect('localhost', 'db', 'db');

  if (!$db)
  {
     print 'Error: Could not connect to database. Please try again later.';
     exit;
  }
  
  $result = mysql_query("mysqldump --opt isas > c:/backup-file.sql") or die (mysql_error());
  
  if($result) {
  	echo 'dump successful';
  } else {
  	echo 'failed';
  }
  
?>

Posted: Wed Jun 07, 2006 6:24 am
by anjanesh
mysqldump is a command line tool. Cant use it as a SQL statement in mysql_query.

Code: Select all

shell_exec("mysqldump --opt isas > c:/backup-file.sql")