views:

45

answers:

2

Is it possible to, from within a PHP script, execute the same commands you could with the MySQL client?

I know I could theoretically call 'system' to invoke the mysql client installed on the system, but I am not sure how to avoid interactivity (I don't want a REPL/shell, I just want to fire a command). Is there a way to execute commands via the mysql client without going into the shell? In either case this approach seems a bit sketchy.

To clarify, when I say command I am referring to the follow: http://dev.mysql.com/doc/refman/5.0/en/mysql-commands.html

A: 

Sounds hacky. There's Expect to handle "programming interactivity", i.e. a way to wait for the prompt to say particular things. I don't think exec will work, unless you can pass specific switches and run mysql in a non-interactive mode. Depending on what you're trying to do I'd say it best to try and figure out a SQL command you can send through the regular client libs.

Robin
+1  A: 
while ($obj = mysql_fetch_object($res)) {
        $file = $path.$obj->base.".sql";
        $cmd = "rm -f ".$file;
        exec($cmd);
        $cmd = "nice -19 mysqldump -h".$host." -u".$login." -p".$pass." ".$obj->base." > ".$file;
        exec($cmd);
        $sql = "update save_mysql set last_daily=NOW() where base = '".$obj->base."'";
        mysql_query($sql);
}

Are you looking for something like this.

using exec function you can call mysql command`

zod
Could you indent your code 4 spaces? Select the chunk, and click the `1010` button. This will make it nicely formatted and easy to read.
Slokun
now read!!! thanks for the info anyway . :)
zod