|
Posted by Phil Latio on 09/26/19 11:48
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
Navigation:
[Reply to this message]
|