Variable Scope with require_once

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux