• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 366
  • Last Modified:

PHP Set Variable

I am trying to convert one of my shell scripts to php, but not sure how to set a particular variable. Currently, this is what I have in my shell script:

MYSQL="$(which mysql)"

How can I code this in php?

0
plecostomus
Asked:
plecostomus
  • 4
  • 3
3 Solutions
 
rogerardCommented:
$MYSQL="which mysql"
0
 
plecostomusAuthor Commented:
I tried the following, but just got this: which mysql
<?php
  $mysql="which mysql";
  echo $mysql;
?>

Open in new window

0
 
rogerardCommented:
Correct.  In your original example, It looks like
MYSQL <- is a variable being assigned information
"$(which mysql)" <-- is a string that contains the address of the mysql server.

so
$mysql = "which mysql"
would accomplish the same thing.  Now if $(which mysql) is a function returning a string then the statement should be
$mysql = which mysql
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
plecostomusAuthor Commented:
Ok... I figured it out...
<?php

 $mysql = shell_exec('which mysql');
 echo $mysql

?>

Open in new window

0
 
rogerardCommented:
Excellent.  Good luck!
0
 
plecostomusAuthor Commented:
no objection
0
 
plecostomusAuthor Commented:
This was the one that helped:

<?php

 $mysql = shell_exec('which mysql');
 echo $mysql

?>
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now