Jump to content

Get MySQL path as a $var


robembra

Recommended Posts

$sql = mysql_query('SELECT @@basedir as dir');
$row = mysql_fetch_array($sql);
echo $row['dir'];

 

I found a small update to the query... but as for your question I don't know...

 

This outputted:

 

/usr/local/

 

At least I'm a step closer I just need "bin" on the end  :-[ 

 

Would mysql always be installed */bin/mysql is that why its output is /usr/local/ or am I not getting the correct output???

 

Thanks again

 

Yes mysql's startup is kinda hinkey stuff -- it's just scripts, but they do append a /bin onto the end of basedir.  It's kind of silly that there isn't a system variable in mysql that shows you the path to the binary, but ... oh well. 

 

Of course it's not really clear why you need to know this.  For example, there could easily be a php install that has no mysql binaries available, and only the client librariy, because the webserver is connecting to a mysql server on a  different host.

 

 

My main reasion is to use mysqldump as it needs the path on some hosts:

 

e.g. /usr/local/bin/mysqldump -h $hostname -u $username --password=$password $dbname | gzip > $mysqldump

Link to comment
Share on other sites

Hey one last thing about the prior discussion of whereis... if you run it with the -b switch it will only look for binaries.    You can also capture the output directly into a string using the backtick operator.

 

$out = `whereis -b mysql`;
echo $out.

 

You still have to parse off the front mysql: and explode out the findings, in case it returns multiples.

Link to comment
Share on other sites

Hey one last thing about the prior discussion of whereis... if you run it with the -b switch it will only look for binaries.    You can also capture the output directly into a string using the backtick operator.

 

$out = `whereis -b mysql`;
echo $out.

 

You still have to parse off the front mysql: and explode out the findings, in case it returns multiples.

 

That outputs...

 

mysql:

 

No path tho :(

Link to comment
Share on other sites

Yes probably.  Fastcgi is often used in shared hosting environments, so that they can utilize suexec support in apache.  This basically allows them to run apache vhosts as your hosting user, rather than having everyone share the global apache user needed with mod_php.  Since your user is probably quite limited as to programs you can see if you were in a shell, php is likewise limited as to what files it can see, exec, etc.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.