Solved

PHP Set Variable

Posted on 2010-11-09
7
359 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
ID: 34096716
$MYSQL="which mysql"
0
 

Author Comment

by:plecostomus
ID: 34096778
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
ID: 34096818
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Accepted Solution

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

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

?>

Open in new window

0
 
LVL 7

Expert Comment

by:rogerard
ID: 34096962
Excellent.  Good luck!
0
 

Author Comment

by:plecostomus
ID: 34099305
no objection
0
 

Author Closing Comment

by:plecostomus
ID: 34130259
This was the one that helped:

<?php

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

?>
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Permalink issue in Wordpress archive 1 33
change password links 7 74
Paypal 502 Error 3 74
WordPress TK Title 8 25
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…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

920 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

19 Experts available now in Live!

Get 1:1 Help Now