[php]
class database{
function __construct(){
$this->connect_id = mysql_connect(' localhost','roo t','');
if($this->connect_id){
if (mysql_select_d b('dbname')) return $this->connect_id;
else return $this->error();
}else return $this->error();
}
function query($query){
if ($query != NULL){
$this->query_result = mysql_query($qu ery, $this->connect_id);
if(!$this->query_result ){
return false;
}else{
return $this->query_result ;
}
}else{
return false;
}
}
}
[/php]I want to access query from other class like this:
[php]
database::query ("UPDATE users SET ....");
[/php]but I can't access it, any ideas? I think I should update database class because I read somewhere that I can't access $this-> from other class..
edit: I know about this solution
[php]
$db = new database();
$db->query...
[/php]and it works, but I don't know, I don't like when I need to "recreate" class..
class database{
function __construct(){
$this->connect_id = mysql_connect(' localhost','roo t','');
if($this->connect_id){
if (mysql_select_d b('dbname')) return $this->connect_id;
else return $this->error();
}else return $this->error();
}
function query($query){
if ($query != NULL){
$this->query_result = mysql_query($qu ery, $this->connect_id);
if(!$this->query_result ){
return false;
}else{
return $this->query_result ;
}
}else{
return false;
}
}
}
[/php]I want to access query from other class like this:
[php]
database::query ("UPDATE users SET ....");
[/php]but I can't access it, any ideas? I think I should update database class because I read somewhere that I can't access $this-> from other class..
edit: I know about this solution
[php]
$db = new database();
$db->query...
[/php]and it works, but I don't know, I don't like when I need to "recreate" class..
Comment