passing a mysqli object via globals

From: Date: Mon, 03 Dec 2007 09:18:42 +0000
Subject: passing a mysqli object via globals
Groups: php.db 
Request: Send a blank email to php-db+get-44377@lists.php.net to get a copy of this message
warn: already posted in general.... with no response... maybe is too basic.. but I RTFM and still is not clear to me what I am doing wrong.... 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 require_once ('file.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 file.php class obj_x{
    function load(){
        globals $db;
        $sql="select ....);
        $ret=$db->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

« previous php.db (#44377) next »