Re: sql query successful

From: Date: Wed, 18 Jul 2001 19:48:03 +0000
Subject: Re: sql query successful
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-58508@lists.php.net to get a copy of this message
Tyler Longren pressed the little lettered thingies in this order... > What about when DELETING from a table??? It always returns true. > Example...the highest ID in this table is 10: > > <? > if ($connection = mysql_connect("localhost","mysql","mysql")) { > print "Connection established"; > $db = mysql_select_db("aanr", $connection); > if ($sql = mysql_query("DELETE FROM bullitens WHERE id='1212'")) { > print "Successful"; > } > else { > print "Not successful."; > } > } > else { > print "Connection NOT established."; > } > ?> > > We try to delete the bulliten with id of 1212, but there is not bulliten > with that ID, and it says "Successful". > > I know I could use mysql_affected_rows(), but why doesn't this work??? > mysql_query() is not intended to be used as a means by which you can check the number of rows that are affected. If it returned FALSE severy time your query was empty, you would have to rewrite all of your of code to eliminate errors. It only checks for the validity of your query. To ask why this doesn't work would be the same thing as asking why you can type this query from the command-line mysql client and the query succeeds without an error. It succeeds and says "0 rows." It's a valid query with zero results. A FALSE return from a programming function indicates an error condition, not the lack of results. Christopher Ostmo a.k.a. tech@AppIdeas.com AppIdeas.com Innovative Application Ideas Meeting cutting edge dynamic web site needs since the dawn of Internet time (1995) For a good time, http://www.AppIdeas.com/

« previous php.general (#58508) next »