Re: mysql dump creates empty file
am 10.09.2006 15:10:54 von Shion
vesakilp@gmail.com wrote:
> I've got this problem: I'm trying to backup a table from my database to
> a .sql file. I'm running mysqldump command from php file, and the
> result file is empty. Where's the problem?
>
> Code:
>
> include "settings.inc";
> include "db.php";
>
> global $dbase;
> global $duser;
> global $dpass;
>
> DBConnect();
>
> $backup = "mysqldump -h localhost -u $duser -p $dpass $dbase table_name
>> backup/table_name.sql";
> shell_exec($backup);
>
> DBClose();
> ?>
>
In theory this should work, but change your shell_exec($backup); to
$error_message=shell_exec($backup);
echo "Command used: ".$backup."
\nOutput from command:
".$error_message."
\n";
in your script, and then you see how your command line looks like and what the
command does output. By the way, as you are using the mysqldump command, you
don't need to connect to the database in the php script.
At least in the mysql command you don't have spaces between -u and the
password, the same for -p too and most likely for the -h too.
$backup = "mysqldump -hlocalhost -u$duser -p$dpass $dbase table_name >
backup/table_name.sql";
//Aho
Re: mysql dump creates empty file
am 10.09.2006 15:48:11 von vesakilp
> In theory this should work, but change your shell_exec($backup); to
>
>
> $error_message=shell_exec($backup);
> echo "Command used: ".$backup."
\nOutput from command:
> ".$error_message."
\n";
>
> in your script, and then you see how your command line looks like and what the
> command does output. By the way, as you are using the mysqldump command, you
> don't need to connect to the database in the php script.
>
> At least in the mysql command you don't have spaces between -u and the
> password, the same for -p too and most likely for the -h too.
>
> $backup = "mysqldump -hlocalhost -u$duser -p$dpass $dbase table_name >
> backup/table_name.sql";
>
>
> //Aho
Well I did as told, and this was result:
Code:
include "settings.inc";
global $dbase;
global $duser;
global $dpass;
$backup = "mysqldump -hlocalhost -u$duser -p$dpass $dbase table >
backup/table.sql";
$error_message = shell_exec($backup);
echo "Command used: ".$backup."
\nOutput from command:
".$error_message."
\n";
?>
Error message:
Command used: mysqldump -hlocalhost -u -p
> backup/table.sql
Output from command:
So there wasn't any out put from $error_message. File was still
created, but it was empty. Starting to piss me off.
By the way, same mysqldump script works fine when executed in console.
Re: mysql dump creates empty file
am 10.09.2006 17:20:45 von Shion
vesakilp@gmail.com wrote:
> Error message:
> Command used: mysqldump -hlocalhost -u -p
> > backup/table.sql
> Output from command:
>
> So there wasn't any out put from $error_message. File was still
> created, but it was empty. Starting to piss me off.
> By the way, same mysqldump script works fine when executed in console.
You haven't disabled shell_exec() in your php.ini for the Apache or in your
Apache configurations VirtualHost tag?
//Aho
Re: mysql dump creates empty file
am 10.09.2006 19:53:19 von vesakilp
J.O. Aho kirjoitti:
> vesakilp@gmail.com wrote:
>
> > Error message:
> > Command used: mysqldump -hlocalhost -u -p
> > > backup/table.sql
> > Output from command:
> >
> > So there wasn't any out put from $error_message. File was still
> > created, but it was empty. Starting to piss me off.
> > By the way, same mysqldump script works fine when executed in console.
>
> You haven't disabled shell_exec() in your php.ini for the Apache or in your
> Apache configurations VirtualHost tag?
>
>
> //Aho
Not intentionally, at least... How can I check that?
Re: mysql dump creates empty file
am 10.09.2006 19:56:22 von Shion
vesakilp@gmail.com wrote:
> J.O. Aho kirjoitti:
>>> So there wasn't any out put from $error_message. File was still
>>> created, but it was empty. Starting to piss me off.
>>> By the way, same mysqldump script works fine when executed in console.
>> You haven't disabled shell_exec() in your php.ini for the Apache or in your
>> Apache configurations VirtualHost tag?
> Not intentionally, at least... How can I check that?
grep for disable_functions in your php.ini (noticed that this one can't be set
in the apache config file as other like open_basedir).
//Aho
Re: mysql dump creates empty file
am 10.09.2006 20:06:15 von vesakilp
J.O. Aho kirjoitti:
> vesakilp@gmail.com wrote:
> > J.O. Aho kirjoitti:
>
> >>> So there wasn't any out put from $error_message. File was still
> >>> created, but it was empty. Starting to piss me off.
> >>> By the way, same mysqldump script works fine when executed in console.
> >> You haven't disabled shell_exec() in your php.ini for the Apache or in your
> >> Apache configurations VirtualHost tag?
> > Not intentionally, at least... How can I check that?
>
> grep for disable_functions in your php.ini (noticed that this one can't be set
> in the apache config file as other like open_basedir).
>
>
> //Aho
did that, still gives empty file
Re: mysql dump creates empty file
am 10.09.2006 20:14:44 von vesakilp
vesakilp@gmail.com kirjoitti:
> J.O. Aho kirjoitti:
>
> > vesakilp@gmail.com wrote:
> > > J.O. Aho kirjoitti:
> >
> > >>> So there wasn't any out put from $error_message. File was still
> > >>> created, but it was empty. Starting to piss me off.
> > >>> By the way, same mysqldump script works fine when executed in console.
> > >> You haven't disabled shell_exec() in your php.ini for the Apache or in your
> > >> Apache configurations VirtualHost tag?
> > > Not intentionally, at least... How can I check that?
> >
> > grep for disable_functions in your php.ini (noticed that this one can't be set
> > in the apache config file as other like open_basedir).
> >
> >
> > //Aho
>
> did that, still gives empty file
allthought i'm not quite sure that I did what you asked me to, I just
put ; in front of disable_functions line in php.ini, don't really know
what's that grepping you're talking about, might have something to do
with linux shell but I'm using XP....
Re: mysql dump creates empty file
am 10.09.2006 20:32:06 von vesakilp
vesakilp@gmail.com kirjoitti:
> vesakilp@gmail.com kirjoitti:
>
> > J.O. Aho kirjoitti:
> >
> > > vesakilp@gmail.com wrote:
> > > > J.O. Aho kirjoitti:
> > >
> > > >>> So there wasn't any out put from $error_message. File was still
> > > >>> created, but it was empty. Starting to piss me off.
> > > >>> By the way, same mysqldump script works fine when executed in console.
> > > >> You haven't disabled shell_exec() in your php.ini for the Apache or in your
> > > >> Apache configurations VirtualHost tag?
> > > > Not intentionally, at least... How can I check that?
> > >
> > > grep for disable_functions in your php.ini (noticed that this one can't be set
> > > in the apache config file as other like open_basedir).
> > >
> > >
> > > //Aho
> >
> > did that, still gives empty file
>
> allthought i'm not quite sure that I did what you asked me to, I just
> put ; in front of disable_functions line in php.ini, don't really know
> what's that grepping you're talking about, might have something to do
> with linux shell but I'm using XP....
Solved it!!! I had to put the directory, where mysqldump command is, in
string that was executed:
$backup = "c:\wamp\mysql\bin\mysqldump -hlocalhost -u$duser -p$dpass
$dbase table_name > backup/table_name.sql";
shell_exec($backup);
In windows shell, command has to be driven from the directory where it
is, of course, so simple. But how can I make it work on Unix server....?
Re: mysql dump creates empty file
am 10.09.2006 21:22:28 von Shion
vesakilp@gmail.com wrote:
> vesakilp@gmail.com kirjoitti:
>
>> vesakilp@gmail.com kirjoitti:
>>
>>> J.O. Aho kirjoitti:
>>>
>>>> vesakilp@gmail.com wrote:
>>>>> J.O. Aho kirjoitti:
>>>>>>> So there wasn't any out put from $error_message. File was still
>>>>>>> created, but it was empty. Starting to piss me off.
>>>>>>> By the way, same mysqldump script works fine when executed in console.
>>>>>> You haven't disabled shell_exec() in your php.ini for the Apache or in your
>>>>>> Apache configurations VirtualHost tag?
>>>>> Not intentionally, at least... How can I check that?
>>>> grep for disable_functions in your php.ini (noticed that this one can't be set
>>>> in the apache config file as other like open_basedir).
>>>>
>>>>
>>>> //Aho
>>> did that, still gives empty file
>> allthought i'm not quite sure that I did what you asked me to, I just
>> put ; in front of disable_functions line in php.ini, don't really know
>> what's that grepping you're talking about, might have something to do
>> with linux shell but I'm using XP....
Okey, assumed you used linux or any other unix like OS, not that often someone
uses "shell" in microsoft.
There is a command named grep that searches for an expression in files
grep disable_functions php.ini
if there would be a line that contains "disable_functions" in the php.ini
file, then you would be given the whole line.
> Solved it!!! I had to put the directory, where mysqldump command is, in
> string that was executed:
>
> $backup = "c:\wamp\mysql\bin\mysqldump -hlocalhost -u$duser -p$dpass
> $dbase table_name > backup/table_name.sql";
> shell_exec($backup);
>
> In windows shell, command has to be driven from the directory where it
> is, of course, so simple. But how can I make it work on Unix server....?
On a unix like system you usually have the $PATH variable in the shell that
gives you which directories it will look into to find the command, of course
the $PATH can be different depending which user you are, you may assume that
the "webserver user" has a normal $PATH and then you don't give a path, but if
you want to be sure, you should give the path, the file in question is usually
in /usr/bin/mysqldump or in /usr/local/bin/mysqldump, depending a little bit
on the os/distro and if the admin has compiled it themselves, using the binary
from mysql.com or uses the one thats shipped with the OS.
You can make the path detection a bit automatic and use is_file, if you don't
want to hardcode the path.
//Aho