was I bitchy? (was: Re: [thelist] webmonkey redesign)

Jay Greenspan jay at trans-city.com
Thu Jun 14 15:53:04 CDT 2001


It's really figgin hot and I still tend to be a bit defensive of 'da monkey.

I can write a tip now that I have my AC installed.

<tip type="PHP" author="jay Greenspan">

A couple of weeks ago, I mentioned that using an "or die" suffix to a
mysql_query() function will give you meaningful errors. Well, there's no
need to type "or die" with every query. Use a function. And in that
function, make sure you give yourself that ability to turn off the error
reporting. When the site's live, you don't want your queries becoming public
knowledge.


function safe_query($sql_string) {
    if ($query_debug != "ON"){
        $result = mysql_query($sql_string) or
            die ("There was an error accessing this page,
                Please contact administrator");

    } elseif ($query_debug == "ON"){

        $result=mysql_query($sql_string) or
            die ("The following query failed:" . $sql_string . "<br>\n"
                    . "With following error:" . mysql_error()
                );

    }

}


</tip>






More information about the thelist mailing list