Re: problems accesing an object via globals

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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);

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux