Jump to content

Recommended Posts

I was tired of having to type out the same code over and over to report mysql errors  while indicating where they occur.  So I decided to write my own function to handle the errors.  However, it doesn't seem to be working properly. 

 

 

function DbQuery($query, $file, $line){

    

    if($execute = mysql_query($query)){

        

        return $execute;

    

    } else {

        

        return '

                        <p>You have an error in a mysql query.</p>

                        

                        <p>File: '.$file.'</p>

                        <p>Line: '.$line.'</p>

                        

                        <p>Query: '.$query.'</p>

                        ';

                        

    }

}

 

I tested it out with this bit of code.  When everything is ok with the query itself, the function works perfectly.  If there is a syntax error, I get a php error saying that mysql_num_rows expects parameter 1 to be resource... which I know why, but I can't figure out how to skip that part, and go right to my custom error.

 

 

$query = DbQuery("

            SELECT

                member_id,                email_address,

                recieve_member_emails,      recieve_admin_emails

            FROM ".DB_PREFIX."members

            WHERE member_id = ".$mbr['id']."

            LIM 1", __FILE__, __LINE__);

            

        if(mysql_num_rows($query) > 0){

            

            $member = mysql_fetch_assoc($query);

            var_dump($member);

            

        }

 

Thank you for your time.

Link to comment
https://forums.phpfreaks.com/topic/275353-custom-mysql-function-w-error-handling/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.