Re: problems accesing an object via globals

From: Date: Sat, 01 Dec 2007 17:35:20 +0000
Subject: Re: problems accesing an object via globals
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-265366@lists.php.net to get a copy of this message
julian wrote:
I want to open a database connection at program initialization and use that very same connection via globals initilizating ( loading from db) other objects. Basically index.php $db=new mysqli(host,us,pass,db); if(mysqli_connect_errno()){
    die('errordb conex');
} switch ($var){
    display1:
        $obj=new obj_x();
        $obj->load();
        $obj->display();
        break;
    display2:
        $obj=new obj_y();
        $obj->load();
        $obj->display();
        break;
       }
------------------ class obj_x{
    function load(){
        globals $db;
        $sql="select ....);
        $ret=$->query($sql); // XX
        ...
        }
} fails at XX with Warning: mysqli::query() [function.mysqli-query]: Couldn't fetch mysqli in class file .... line XX Any hints ??. I am using php 5.1.6 with linux/ubuntu. Thanks. JCG
there is typo. obviously I try to access via $db->query($sql);

« previous php.general (#265366) next »