views:

58

answers:

2

Hi guys,

I need to run Shell_exec to import a dump into my MYSQL database. Today I do this:

$shellExec = 'C:\wamp\bin\mysql\mysql5.1.36\bin\mysql -h localhost -u root mertero_decicare < D:\localhost\sql\decisions.sql';

$out = shell_exec($shellExec .' 2> output');

Which works. But is there a way to 'find' the location of the mysql executable from PHP? SO I don't need to hardcaord my mysql location?

Ron

A: 

On Windows to could add C:\wamp\bin\mysql\mysql5.1.36\bin\ to you Environment Variables path. See: http://en.wikipedia.org/wiki/Environment_variable

That way you could just call shell_exec('mysql ...');

Alernatively you could not use mysqldump, you could use SELECT INTO OUTFILE in MySQL although you'd need to do it for each table. Not as elegant as mysqldump.

robdog
Thanks - but it doesn't really help, as I want my script to be used on many computers, and this requires another step in 'installation' which I'm trying to avoid in the first place...
Ron Mertens
+1  A: 

An easy way to do this is add it to the Windows Environment path (it is in the path on most Unix systems). Then you just have to call mysql from the script.

Here is the information page on how to do it from MySQL: MySQL Windows Service Start

And on that page you want to find the text

"To make it easier to invoke MySQL programs, you can add the path name of the MySQL bin directory to your Windows system PATH environment variable"

and read through that section. Using this method you just have to call mysql without a path.

Brad F Jacobs
Thanks - but it doesn't really help, as I want my script to be used on many computers, and this requires another step in 'installation' which I'm trying to avoid in the first place...
Ron Mertens