Variable Scope with require_once
| From: | user at domain dot invalid | Date: | Mon, 27 Apr 2009 14:28:21 +0000 |
| Subject: | Variable Scope with require_once | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-292023@lists.php.net to get a copy of this message | ||
Hello, all.
I have a working app that runs in PHP 4.4.9 on the server. I develop the app on my local environment, which runs PHP 5.2.6.
The setup is thus:
From my index, I have
require_once('config.php');
require_once('dbstuff.php');
config.php looks like this:
<?php
$db_host = 'localhost';
$db_user = 'someuser';
$db_password = 'somepassword';
$
...snipped...
?>
dbstuff.php looks like this:
<?php
if( !$dbh ) {
$dbh = mysql_connect($db_host, $db_user, $db_password) or die('Could not connect: ' . mysql_error());
}
...snipped...
?>
For some reason, the $db_host, $db_user, and so on defined in config.php are not accessible from dbstuff.php on my development environment. I wlll get
[timestamp] [error] [client 127.0.0.1] PHP Notice: Undefined variable: db_host in somepath\db_stuff.php on line whatever
which causes
'Could not connect: some MySQL error message that is obtained when attempting to login with a nonexistent user'
This works on the production environment (the one with PHP version 4.4.9). register_globals is Off in both environments.
What is going on, here?
Regards,
A. Wilson