Re: RE: [PEAR] 2 newbie Qs: DB_DataObjects

From: Date: Wed, 15 Jun 2005 17:20:28 +0000
Subject: Re: RE: [PEAR] 2 newbie Qs: DB_DataObjects
References: 1 2  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-19640@lists.php.net to get a copy of this message
Thanks Dan, Justin; Cast does work perfectly: now I just have to persuade my group to use it. (And Justin, tx for the tip re: 'update()'. I picked that up from a tutorial, and thought it was required.) I'm having trouble, though, reproducing the behavior you both say should happen on inserts. My table has a primary key ('ID') with no auto-increment, and a second, unique index on Email. Here's what I'm finding: DB_DataObject::debugLevel(5); $person = DB_DataObject::Factory('users'); $person->FName = "Dummy"; $person->LName = "User"; $person->Salutation = "Mr."; $person->Email = "Dumuser@somewhere.edu"; $person->Phone = "999.999.9999"; $person->PostalAddress = "Address"; $person->Password = md5('dummypass'); $person->Type = 0; $person->Active = TRUE; $person->fromValue('CreateDate',DB_DataObject_Cast::sql("NOW()")); $ID = $person->insert(); produces: Users: Query Error: [db_error: message="DB Error: already exists" code=-5 mode=return level=notice prefix="" info="INSERT INTO users (Password , Type , Active , LName , FName , Salutation , Email , Phone , PostalAddress , CreateDate ) VALUES ('4518bda19425be276817a3b3eeee82b8' , 0 , 1 , 'User' , 'Dummy' , 'Mr.' , 'Dumuser3@somewhere.edu' , '999.999.9999' , 'Address' , '2005-06-15 13:05:17' ) [nativecode=1062 ** Duplicate entry '0' for key 1]"] I can't see any sign that the query even attempts to set ID. The email address is definitely unique. The query succeeds when I empty the table, but fails if there is even one record in the table already. Emptying the table resets the DB_DO internal sequence to '0', which isn't the documented behavior for PEAR sequences, I believe? Also, the returned value $ID from insert() is always '1', no matter what the actual value of ID in the table. What am I missing? And is there a really good tutorial I can pick up somewhere, to get myself up to speed more fully? tx again! --CJ

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