cgm225 Posted March 31, 2008 Share Posted March 31, 2008 I have the following code:: require_once PAGE_DIR . "/GeneralConfigurations.php5"; //This has my database connection settings, etc. //Requiring the front controller class require_once "FrontController.php5"; FrontController::createInstance()->dispatch(); In my configuration file I have some general settings, including my database configurations. However, when I try to use these variables in my front controller class, I cannot access them. I think it is a scope issue/something to do with globals, but I am not sure what is going on/how to fix it. Any ideas? Thank you all in advance! Link to comment https://forums.phpfreaks.com/topic/98838-having-issues-with-scope-trying-to-use-general-configuration-file-within-class/ Share on other sites More sharing options...
BlueSkyIS Posted March 31, 2008 Share Posted March 31, 2008 how are you declaring/defining your database settings? Link to comment https://forums.phpfreaks.com/topic/98838-having-issues-with-scope-trying-to-use-general-configuration-file-within-class/#findComment-505746 Share on other sites More sharing options...
cgm225 Posted March 31, 2008 Author Share Posted March 31, 2008 My GeneralConfiguration.php file: /* Database connection settings */ $mysql_server_1 = "mysql.internal"; $mysql_server_1_username = "user"; $mysql_server_1_password = "password"; $gallery_database = "gallery"; Then I connect to it in a file INCLUDED by the class as such: $mysql_server_connection_1 = mysql_connect($mysql_server_1,$mysql_server_1_username,$mysql_server_1_password,TRUE); mysql_select_db($gallery_database, $mysql_server_connection_1); Link to comment https://forums.phpfreaks.com/topic/98838-having-issues-with-scope-trying-to-use-general-configuration-file-within-class/#findComment-505751 Share on other sites More sharing options...
BlueSkyIS Posted March 31, 2008 Share Posted March 31, 2008 if you want your db vars to be globally available, i would define them as constants: define(MYSQL_SERVER, "mysql.internal"); define(MYSQL_USER, "user"); define(MYSQL_PASS, "password"); define(MYSQL_DB, "gallery"); and alter all connect code to: $mysql_server_connection_1 = mysql_connect(MYSQL_SERVER, MYSQL_USER, MYSQL_PASS,TRUE); mysql_select_db(MYSQL_DB, $mysql_server_connection_1); Link to comment https://forums.phpfreaks.com/topic/98838-having-issues-with-scope-trying-to-use-general-configuration-file-within-class/#findComment-505753 Share on other sites More sharing options...
cgm225 Posted March 31, 2008 Author Share Posted March 31, 2008 Even with constants, I still get: Notice: Use of undefined constant MYSQL_SERVER_1 - assumed 'MYSQL_SERVER_1' in /web/example.com/DEVELOPMENT/GeneralConfigurations.php5 on line 10 Link to comment https://forums.phpfreaks.com/topic/98838-having-issues-with-scope-trying-to-use-general-configuration-file-within-class/#findComment-505761 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.