Variable Scope Problem
Posted: Tue Apr 13, 2004 12:46 pm
Rather than using PEAR I have created my own script to handle MySQL actions. I did this using OOP, and the class' called 'class_mysql'. I'm using this script to access data in the database in a user management (login) system. I created another sets of functions using OOP which has all the functions I need to manage users such as log-in, log-out, register, ban etc.
Problem comes here...
In the user management class I have a function called init(); which obviously is called before any other functions are run and in the function I load the MySQL script like so:
Config.php:-
Now connect function in MySQL class:-
Error message from MySQL says that it execute sql queries later in the script because a database has not been selected. I'm using local MySQL server with no password so I think that's why the error is not caught in the connect() function...
Using a debugger I found out that the variable $config suddenly dissapears once its in mysql class. Its there in the usrmanage class but then it dissappears. Is this a problem with my variable scopes?
Thanks for you help in advance,
RadixDev
Problem comes here...
In the user management class I have a function called init(); which obviously is called before any other functions are run and in the function I load the MySQL script like so:
Code: Select all
<?php
class usrmanage {
function init($dir="") {
include($directory."config.php"); // MySQL Configuration
include($directory."mysql.php"); // MySQL class
$this->con=new class_mysql();
$this->con->connect($directory); //connects to MySQL using config in config.php
//$directory is used to identify the folder in which the files which will be included in the MySQL script exists.
}
}
?>Code: Select all
<?php
$config['mysql']['host']="localhost";
$config['mysql']['username']="root";
$config['mysql']['password']="";
$config['mysql']['database']="radix";
$config['mysql']['prefix']="rdxls_";
?>Code: Select all
<?php
class class_mysql() {
var $root;
function connect($dir="") {
$this->root=$dir;
include_once($dir."config.php");
@mysql_connect($config['mysql']['host'], $config['mysql']['username'], $config['mysql']['password']);
@mysql_select_db($config['mysql']['database']);
}
}
?>Using a debugger I found out that the variable $config suddenly dissapears once its in mysql class. Its there in the usrmanage class but then it dissappears. Is this a problem with my variable scopes?
Thanks for you help in advance,
RadixDev