Defining variables in a seperate file



I am missing a trick here on how use variables defined in seperate file.

In script 1, I have proved to myself my class is working OK because I can
pass in the values and the echo statement outputs the value of localhost.

<?php
// Script 1
// This script works and outputs the name of localhost
require_once("class.MySQL.php");
$db = new MySQL("localhost", "user", "password", "database");
echo "Name of host: ".$db->host;
?>

However if I assign these values in a seperate file called configuration.php
and put the $variable names in the instantiation statement, it doesn't seem
to work. Can't understand why it doesn't work because I reckon it should
still be passing in the values of $localhost, $user, $password and $database
which is exactly as script 1.

<?php
/* Script 2
This script does not seem assign a value to $localhost
Here is the contents of config.php without the open/close PHP tags.
$host = "localhost";
$user = "user";
$password = "password";
$database = "database"; */

require_once("configuration.php");
require_once("class.MySQL.php");
$db = new MySQL($localhost, $user, $password, $database);
echo "Name of host: ".$db->host;
?>

Appreciate any comments. I am sure I have overlooked something very obvious.

Cheers

Phil



.



Relevant Pages

  • Re: How to call perl with in-line contents?
    ... > this easily by creating a seperate perl script. ... I should not write a seperate file to do this processing. ... > I am calling the perl from a shell script. ...
    (perl.beginners)
  • Re: How to call perl with in-line contents?
    ... >by creating a seperate perl script. ... >write a seperate file to do this processing. ... >I am calling the perl from a shell script. ...
    (perl.beginners)
  • RE: How to call perl with in-line contents?
    ... > this easily by creating a seperate perl script. ... I should not write a seperate file to do this processing. ... > I am calling the perl from a shell script. ...
    (perl.beginners)
  • Sessions in object oriented code
    ... cookies and sessions for my script, whereby the user is allowed to choose ... registration form, etc., from those that are logged in. ... form is in its own method in a seperate file, ...
    (php.general)
  • How to call perl with in-line contents?
    ... easily by creating a seperate perl script. ... should not write a seperate file to do this processing. ... I am calling the perl from a shell script. ...
    (perl.beginners)