Solved

PHP Set Variable

Posted on 2010-11-09
7
358 Views
Last Modified: 2012-06-22
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
Comment
Question by:plecostomus
  • 4
  • 3
7 Comments
 
LVL 7

Assisted Solution

by:rogerard
rogerard earned 500 total points
Comment Utility
$MYSQL="which mysql"
0
 

Author Comment

by:plecostomus
Comment Utility
I tried the following, but just got this: which mysql
<?php
  $mysql="which mysql";
  echo $mysql;
?>

Open in new window

0
 
LVL 7

Assisted Solution

by:rogerard
rogerard earned 500 total points
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Accepted Solution

by:
plecostomus earned 0 total points
Comment Utility
Ok... I figured it out...
<?php

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

?>

Open in new window

0
 
LVL 7

Expert Comment

by:rogerard
Comment Utility
Excellent.  Good luck!
0
 

Author Comment

by:plecostomus
Comment Utility
no objection
0
 

Author Closing Comment

by:plecostomus
Comment Utility
This was the one that helped:

<?php

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

?>
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now