Re: DB_DataObject
| From: | Tomek Klas | Date: | Wed, 25 Aug 2004 17:57:47 +0000 |
| Subject: | Re: DB_DataObject | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-14292@lists.php.net to get a copy of this message | ||
Hey,
DB_DataObject::debugLevel(5); produceddataobject_protocols_users: __find: DB_DataObject Error: No database name / dsn found anywhere Function username_exists() is a custom rule in HTML_QuickForm, which checks the username against the database table. The error (as you can see) occurs as soon as the find() method is called. interestingly, after I modified the function to: $user_test = DB_DataObject::factory('protocols_users'); $user_test->username=$element_value; $num_results= $user_test->find(); I get more error info: Notice: Undefined index: class_prefix in <b>/usr/lib/php/DB/DataObject.php on line 2260 Notice: Undefined index: class_location in <b>/usr/lib/php/DB/DataObject.php on line 2267 DB_DataObject: ERROR: autoload:Could not find class Protocols_users using class_location value DB_DataObject: ERROR: factory could not find class from protocols_users Fatal error: Call to undefined function: find() in /Users/communicatehealth/Sites/protocols/register/index.php on line 172 my DB_DataObject ini file [DB_DataObject]
database = mysql://user:pass@localhost/communicateschema_location = /Users/communicatehealth/DB_DataObject class_location = /Users/communicatehealth/DB_DataObject require_prefix = DataObject/
class_prefix = DataObject_debug = 0 and is included in a setup (smarty & pear) file ############################################## ## PEAR::DB_DataObject require_once("/Users/communicatehealth/DB_DataObject/Protocols_users.php"); //Parse the database ini file $dbconfig = parse_ini_file("/Users/communicatehealth/DB_DataObject/db_dataobject.ini", true); // Load database settings foreach( $dbconfig as $class => $values ) { $options = &PEAR::getStaticProperty($class, 'options'); $options = $values; } ## PEAR::DB_DataObject ############################################## which is included in at the beginning of every file. I guess the problem lies in me using that DataObject in a function, as it works just fine once I take it out. The strangest things is, that it actually worked for few hours, and then stopped.... I was curious, and tried to copy that: //Parse the database ini file $dbconfig = parse_ini_file("/Users/communicatehealth/DB_DataObject/db_dataobject.ini", true); // Load database settings foreach( $dbconfig as $class => $values ) { $options = &PEAR::getStaticProperty($class, 'options'); $options = $values; } into my function... and it worked right away.... no errors.... any ideas? t. On 25 Aug 2004, at 17:59, Justin Patrin wrote:
On Wed, 25 Aug 2004 17:41:48 +0100, Tomek Klas <tomek@tomekklas.com> wrote:Hello, I am doing a registration system using DataObject and HTML_QuickForm. It's a bit strange, but all of the sudden, my custom rule stopped working. To be precise, the DataObject inside throws out a message: DB_DataObject Error: No database name / dsn found anywhere Offending script:Likely this isn't your problem, but you're supposed to use the factory to create DataObjects. $check_username = DB_DataObject::factory('protocols_users'); If you do this, you also don't have to (and shouldn't) explicitly include the dataobject file for that table.function username_exists($element_name, $element_value) { $check_username = new DataObject_Protocols_users;At what point does the error happen? Try putting this at the beginning of the function: DB_DataObject::debugLevel(5); Are you sure you're setting up the configuration?$check_username->username=$element_value; $num_results = $check_username->find();if ($num_results == 0) { return true; } else { return false; }}It works just fine once I take the script out of function.... So, what is it, I am missing here?Tomek--DB_DataObject_FormBuilder - The database at your fingertips http://pear.php.net/package/DB_DataObject_FormBuilder paperCrane --Justin Patrin--