Addressed to: "Richard Lynch" <[EMAIL PROTECTED]>
              [EMAIL PROTECTED]

** Reply to note from "Richard Lynch" <[EMAIL PROTECTED]> 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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to