I have a config.php file with:
$globalConf = array( 'DbConfig' => array( 'Hostname' => 'localhost', 'Username' => 'myuser', 'Password' => 'xxxxxxxx', 'Database' => 'mydb' ) ); and in other file (this includes the config.php) i have this function:
function db_connect() { if (!($db_link = mysqli_connect($globalConf['DbConfig']['Hostname'], $globalConf['DbConfig']['Username'], $globalConf['DbConfig']['Password'], $globalConf['DbConfig']['Database']))) exit(); return $db_link; } This doesn't work. I would need to include the global $globalConf inside the db_connect() function, but I don't want to do this (i have more configurations variables and multiple functions that require those and I don't want to use a global $variable in all functions and subfunctions).
I want to set the $globalConf as a persistent global variable (possibly accesible like class?), for example:
mysqli_connect(myglobal::$globalConf['DbConfig']['Hostname']) how can do this?
Solved:
class MainConf { public static $globalConf = array( 'DbConfig' => array( 'Hostname' => 'localhost', 'Username' => 'myuser', 'Password' => 'xxxxxxxx', 'Database' => 'mydb' ) ); } and:
function db_connect() { if (!($db_link = mysqli_connect(MainConf::$globalConf['DbConfig']['Hostname'], MainConf::$globalConf['DbConfig']['Username'], MainConf::$globalConf['DbConfig']['Password'], MainConf::$globalConf['DbConfig']['Database']))) exit(); return $db_link; }