I have a problem with the global scope.
I use a global variable named $db and then I include a DBConnector file that does all the work and initiates the variable as an object. When I print the result in the end of the DBConnector file I see that it was built properly.
But when I return to the original file the object is unset and the system doesn't recognize it!!!!!
My settings file ends with the following lines:
Code: Select all
global $db;
include('DBConnector.php');
echo "$db settings";Code: Select all
if( defined( '_ADMIN_DBCONNECTOR_PHP' ) ) return;
define( '_ADMIN_DBCONNECTOR_PHP', 1 );
include('dblayer.php');
global $db;
$db = new DBLayer();
$db->connect($SQL_SERVER,$SQL_USERNAME,$SQL_PASSWORD,$SQL_DBNAME);
function getNextAutoIncrement($tableName)
{
global $db;
//$sql = "SHOW TABLE STATUS WHERE Name='".$tableName."'";
$sql = "SHOW TABLE STATUS WHERE Name='".$tableName."'";
$tableStatus = array();
$db->Query($tableStatus,$sql);
return $tableStatus[0]['Auto_increment'];
}
echo "$db connector";
"Object connectror settings"
means that the first time I print $db the system recognizes an Object but the second time (in the settings file) it doesn't!!!!
Does anyone know Why?
Thanks
Danny
Everah | Please use the bbCode [code] tag when posting code in the forums. To highlight PHP, please use [code=php].