Re: DataObject DB connection failing

From: Date: Wed, 11 Dec 2002 15:17:32 +0000
Subject: Re: DataObject DB connection failing
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-2944@lists.php.net to get a copy of this message
Hi Mike, If I'm not mistaken, you should run that code (the options thingie) every time you want to use DB_DataObject. You could put it in a init.php file or something, and include it in every php file you are going to use DB_DataObject. As for an explanation of the code: /* make $options a _reference_ to the static property options of DB_DataObject When you change $options from now on, you'll in fact be changing PEAR::getStaticProperty('DB_DataObject','options') */ $options = &PEAR::getStaticProperty('DB_DataObject','options'); /* just set the debugging level to high, can be left out if everything works */ DB_DataObject::debugLevel(5); /* load the ini file in variable $config */ $config = parse_ini_file('redbox_databases.ini', TRUE); /* dump the variable created from the ini file, can be left out */ var_dump($config); /* assign the contents of $config to $options (and in fact to PEAR::getStaticProperty('DB_DataObject','options'), which is used by DB_DataObject) $options = $config['DB_DataObject']; /* imho it is safest to unset the reference, so that if you assign someting else to $options, it won't change the PEAR property */ unset($options); greets, Stijn Mike Carter wrote:
Hi all, Just found this newsgroup and hope that I can get some clues on using PEAR stuff.... it's the DataObject I'm having issues with. I've created all the extended classes based on my database tables. The problem is actually doing the connection when I call a method such as find() or get(). I just get the error message "DB Error: not found". The manual was a little misleading/non-descriptive on how you actually go about using the DataObjects from any scripts/private classes. The manual mentions calling:-
        $options = &PEAR::getStaticProperty('DB_DataObject','options');
        DB_DataObject::debugLevel(5);
        $config = parse_ini_file('redbox_databases.ini', TRUE);
        var_dump($config);
        $options = $config['DB_DataObject'];
Where should this be called? My code that creates instances of DataObjects is, itself, within classes so where should I call this initialisation code? What happens to the $options variable that the init code finishes with? Does this need to be global if I am calling extended DataObject classes from within my own class methods? The manual isn't great for getting people started, I think. Could anybdy explain how things fit together? Regards,


« previous php.pear.general (#2944) next »