Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1047661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:20:12+00:00 2026-05-16T16:20:12+00:00

Does anyone have a PHP function that for example if a mysql_error() happens due

  • 0

Does anyone have a PHP function that for example if a mysql_error() happens due to well a MySQL error it will not output it?

By not output it I mean rather it not show the error on live site as I will use it with another function I have that would work a treat if I had a MySQL error function.

I am just finding it so annoying as I do it like this currently:

$q = mysql_query("SELECT * FROM something");

// if error occurs
if(!$q) {
   echo 'Error' . mysql_error();
} else {
  // else no errors so continue
}

On some of my webpages see I have several queries in a script and I would like to just be able to include the function at the bottom of all my PHP code and if a MySQL error occurs anywhere in my script for the function to catch the error instead of me doing multiples of the code I quoted above.

That way I can save myself a lot of unnecessary work and implement it with my email error function.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T16:20:13+00:00Added an answer on May 16, 2026 at 4:20 pm

    The most robust solution is to probably use trigger_error(). This way you can tie into PHP’s error handling system which is already prepared to deal with development and production environments.

    $querySql = 'SELECT * FROM `foo`';
    $queryResult = mysql_query($querySql);
    
    if (!$queryResult) {
        trigger_error('Unable to execute query: ' . $querySql, E_USER_NOTICE);
    }
    

    Of course, the most convenience would be to make a decorating function for mysql_query() that automatically triggered the error. The DRY principle always applies.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone have any experience using PHP to send an sms via skype I
Does anyone have an idea on where is it best to upload a PHP
Does anyone have a solid benchmark about the speed of parsing PHP code comments?
Does anyone have a translate function for x/y positions after rotation in javascript? for
For example, I have a php function: function DeleteItem($item_id) { db_query(DELETE FROM {items} WHERE
I have this piece of code $.get('/proc.php?proc=get_color', function(data){ $('#offer_color').html(data); }); that is hosted on
Does anyone have recommendations on the best Online Store for non-technical users of Joomla?
Does anyone have any examples on how to integrate a task scheduler in Bottle.
Does anyone have an idea of how to capture logs continuously and update a
does anyone have a nice solution to get de price wich is a variable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.