Re: DB_DataObject::get() always returns true
| From: | Justin Patrin | Date: | Fri, 16 Sep 2005 17:04:36 +0000 |
| Subject: | Re: DB_DataObject::get() always returns true | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-21008@lists.php.net to get a copy of this message | ||
On 9/16/05, Jeff Loiselle <jeff@newnewmedia.com> wrote:
> According to the documentation, this should work:
>
> if ($person->get(12)) {
> print_r($person);
> } else {
> echo "NO person 12 exists";
> }
>
> However, the get method always returns true. Now I believe this is the
> intended behavior, as the class will return a new instance of the
> object, if it does not exist. It also does not supply an error. So, how
> do I check to see if the record actually exists in the database, without
> checking on a specific field?
>
Return a new instance? No, get() never returns any instances. It
returns false if there's an error or the number of rows found (0 if
the record doesn't exist). If you want to see errors you can access
the _lastError property in your DO or turn on debugging.
(DB_DataObject::debugLevel(1);)
--
Justin Patrin