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("c lass.MySQL.php" );
$db = new MySQL("localhos t", "user", "password", "database") ;
echo "Name of host: ".$db->host;
?>
However if I assign these values in a seperate file called configuration.p hp
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("c onfiguration.ph p");
require_once("c lass.MySQL.php" );
$db = new MySQL($localhos t, $user, $password, $database);
echo "Name of host: ".$db->host;
?>
Appreciate any comments. I am sure I have overlooked something very obvious.
Cheers
Phil
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("c lass.MySQL.php" );
$db = new MySQL("localhos t", "user", "password", "database") ;
echo "Name of host: ".$db->host;
?>
However if I assign these values in a seperate file called configuration.p hp
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("c onfiguration.ph p");
require_once("c lass.MySQL.php" );
$db = new MySQL($localhos t, $user, $password, $database);
echo "Name of host: ".$db->host;
?>
Appreciate any comments. I am sure I have overlooked something very obvious.
Cheers
Phil
Comment