Can I automatically locate the MySQL executable from PHP?

给你一囗甜甜゛ 提交于 2019-12-11 09:06:54

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/3309094/can-i-automatically-locate-the-mysql-executable-from-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!