I’m going to backup my database using a php script which executes a command using the system() function. Unfortunately, my shared hosting has disabled it. I got this warning when I ran it:
Warning: system() has been disabled for security reasons in /path-to-my-file on line 162
Here is my piece of code:
$filename = 'backup/mybackupfile.sql';
$command = "mysqldump -u myuser -pmypass mydatabase > ". $filename ."";
system($command);
It is working fine on my local computer with xampp, but it happens to be a problem on my shared hosting.
So, I need another way to run the mysqldump command instead of using system(). I try to avoid using cron or SELECT * OUTFILE things.
As Mrs. Hakra already said, you will not be able to run
mysqldumpat all if your host has disabled the execution of system commands.You will have to ask them to enable system commands, or do a dump using a PHP script. Be very careful with the PHP dump scripts around, however: my experience has shown that many create broken or incomplete dumps.
Some Googling reveals small tools such as this one. But as said, be careful and do some tests to verify accuracy.
The best PHP-based export tool I know that is doing the job properly is that of PhpMyAdmin. Maybe that can help. In theory, it should even be possible to isolate its exporting library, but as far as I know it doesn’t expose it in any easy way for use in other scripts.