Re: DB error
| From: | Justin Patrin | Date: | Tue, 22 Nov 2005 22:45:17 +0000 |
| Subject: | Re: DB error | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-22063@lists.php.net to get a copy of this message | ||
On 11/22/05, Massimiliano Arione <garak@studenti.it> wrote:
> I have a problem with DB error.
>
> Here is a sample of code:
>
> <?php
> [... initialize $db with DB::connect() ]
>
> $res =& $db->query($sql);
>
> if (DB::isError($res)) {
> exit('DB error!')
> }
>
> while ($row =& $res->fetchRow()) {
> [... do something with $row ...]
> }
> ?>
>
> my problem is that sometimes the mysql server lose connection and I have
> a php fatal error ("Call to a member function on a non-object") on the
> line of fetchRow()
>
> Is there any way to avoid this?
>
Your isError call should catch such cases. Try doing a print_r of $res
when such a thing happens to see what it is. Perhaps:
if (!is_a($res, 'DB_Result')) {
print_r($res);
}
to see what's happening.
--
Justin Patrin