Re: mysql_error on an update
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

Re: mysql_error on an update

From: Gordon Burditt <gordonb.r5alm@burditt.org>
Date: Tue Jan 31 2006 - 17:48:45 CET

>What's the best practice for handling the following situation, when I
>do an update like this:
>
>$sql = "UPDATE haha SET papa="loco" WHERE id=$var";
>$res = mysql_query($sql,$db);
>
>If I don't get a match in my where clause, i.e., 12!=44 the UPDATE does
>not occur but mysql_errno == 0 and mysql_error = "" so I can't capture
>the failure.

It's NOT a failure. The query did what you wanted it to.

>From an application point of view, sometimes affecting or
retrieving any rows is a failure (consider black lists).

I believe you can look at mysql_affected_rows() and see how many
rows it changed.

                                        Gordon L. Burditt
Received on Tue Feb 7 21:08:22 2006