Solved

PHP Set Variable

Posted on 2010-11-09
7
360 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

813 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