Re: the best so far

From: Date: Fri, 16 Feb 2001 22:29:23 +0000
Subject: Re: the best so far
Groups: php.general 
Request: Send a blank email to php-general+get-40242@lists.php.net to get a copy of this message
Addressed to: "Richard Lynch" <richard@zend.com> php-general@lists.php.net ** Reply to note from "Richard Lynch" <richard@zend.com> Thu, 15 Feb 2001 19:54:55 -0600 > Does die() give you a line number? If not, just put it in there. No, die() does not add to your message. Here is how I solved the problem: function Query( $Query ) { global $ShowQueries; $Result = mysql_query( $Query ); if( !$Result ) echo( mysql_error() . " in Query at $__LINE__ in $__FILE__<BR>\n$Query<BR>\n" ); elseif( $ShowQueries ) echo( "$Query<BR>\n" ); return( $Result ); } usage: $Result = Query( "SELECT fielda, fieldb. fieldc, fieldd, fielde " . " fieldf, fieldg, fieldh " . "FROM Table1 " . "LEFT JOIN Table2 USING( common_field ) " . "WHERE condition1 = '$Value1' " . " AND condition2 > '$Value2' " . "ORDER BY SortField " ); Every query I've written goes thru this function. A couple of things about this: The queries jump out at you when you are looking at the source code. When you have an error in a query you get the mysql_error() message and the entire query printed just below it. I've found that quite handy for debugging. Almost every one of my programs has #$ShowQueries='on'; very near the top of the file. If I am not sure just what it is doing to the database, I just un-comment this line and each query string is printed as it is executed. I've used it enough that I just add the line in every program, or use a template that includes it. Rick Widmer Internet Marketing Specialists http://www.developersdesk.com

« previous php.general (#40242) next »