Re: If a query fails?
| From: | heilo | Date: | Fri, 09 May 2003 23:52:14 +0000 |
| Subject: | Re: If a query fails? | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-27628@lists.php.net to get a copy of this message | ||
hi
there are several ways to test if the insert/delete/update worked - with
mysql the easiest way is to use mysql_affected_rows() which returns the
number of entrys added/deleted/changed. another way is just to test if the
query worked like
$res = mysql_query($qry);
if(!$res)
die('There was an error: '.mysql_error().'</body></hmlt>');
the most complicated way i think is to make a select after you
added/deleted/updated something and test if the data availiable really is
the data you wanted to insert.
hope this helps?
.ma
Chris Payne <cjp@planetoxygene.com> wrote@10.05.2003 1:45 Uhr:
> Hi there everyone,
>
> Probably something so simple i'll collapse with embarressment, just like with
> my spelling :-) But a quick question, when you perform an update or insert
> etc .... operation on a MySQL Database, how do you find out if it was
> successful or failed, so you can display the correct output? Currently if I
> add to a DB, for example, it goes to a page saying it updated successfully but
> without any error trapping, so even if it DIDN'T do it successfully it would
> still go to the next page.
>
> Thanks for your help :-)
>
> Chris