Re: Stricter Error Checking?

From: Date: Wed, 23 Sep 2009 18:45:50 +0000
Subject: Re: Stricter Error Checking?
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-298298@lists.php.net to get a copy of this message
----- Original Message ---- > From: Bob McConnell <rvm@CBORD.com> > To: Tommy Pham <tommyhp2@yahoo.com>; php-general@lists.php.net > Sent: Wednesday, September 23, 2009 11:37:00 AM > Subject: RE: [PHP] Stricter Error Checking? > > From: Tommy Pham > >> From: Tim Legg > >> > >> I just spent way, way to much time trying to debug code due to a > misnamed > >> element. Here is a simplified example of the problem I dealt with. > >> > >> > >> $test = "SELECT * FROM Materials WHERE > >> Part_Number = > '125664'"; > >> $result = mysql_query($test,$handle); > >> if(!$result) > >> { > >> die('Error: ' . mysql_error()); > >> } > >> $row = mysql_fetch_array($result); > >> echo $row['Number']; > >> > >> After retyping the code 3 or 4 times over the course of the morning, > I finally > >> found where the problem was. The problem is that the database field > is called > >> 'Part_Number', not 'Number'. The field 'Number' does > >> not exist in > the > >> database. I am very surprised that I didn't even get a warning that > there might > >> be a problem with the statement. All I saw is that nothing was being > returned > >> via the echo command. > > > > if(!$result) > > { > > die('Error: ' . mysql_error()); > > } > > > > This didn't work when you used 'Number' instead of 'Part_Number'? > Strange... > > > > I think the problem is that he didn't check that the key he used > actually existed before using the value it pointed to. So he got an > empty string for $row['Number']; because the key should have been > 'Part_Number'. I don't know that even E_STRICT would catch that one. > > Bob McConnell > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php My mistake, didn't have enough caffeine for the day :)

« previous php.general (#298298) next »