Jump to content

Having issues with scope, trying to use general configuration file within class


cgm225

Recommended Posts

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!

 

 

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);

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);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.