Possible to run mysqldump with mysql_query?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
gnel2000
Forum Newbie
Posts: 16
Joined: Tue Jul 26, 2005 10:41 pm

Possible to run mysqldump with mysql_query?

Post 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';
  }
  
?>
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post 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")
Post Reply