Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

PHP Set Variable

Posted on 2010-11-09
7
361 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Why is my wamp get_include_path() wrong? 2 21
PHP error function not working on AWS 10 70
How to delete values from an array using php 4 23
Ahax pagination 9 32
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…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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.

860 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