Hi all,
I've a problem with an external configuration file and a class that need to use some vars configured in this file.
this is the code:

<?php
require_once("../common/configuration/db_config.php");

class sql_functions
{
	function get_connection()
	{
		//Globalize db configuration variables
		global $_db_host, $_db_uname, $_db_pwd, $_db_name;

	//Connect to database
	$conn = mysql_connect($_db_host,$_db_uname,$_db_pwd);
	mysql_selectdb($_db_name,$conn);

	//Return connection
	return $conn;
}

}

?>

I can't access to global variables $db* that are in db_config.php.

Is there anyone that can help me?

    hi,

    use

    $GLOBALS["variablename"]

    or in the config instead of variables, define the constants as follows

    define("dbhot","localhost");
    define("uname","rams");
    define("pword","rams");

    in your file use them in the following manner

    mysql_connect(dbhost,uname,pword)

    regards,
    bvsureshbabu

      What do you get with this code:

      require_once("../common/configuration/db_config.php"); 
      echo $_db_host;

      Edit: If the variables are defined in the included file and are not defined within a function or another class, and the file is actually being included, then using "$_db_host", etc., should work.

        Hi,
        thank all for the help, as suggested from phpprogrammer I've resolved the problem with define() function in configuration file.

        Have a good day!
        (please forgive my english, I'm italian)

          Write a Reply...