Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mySQL errors in php

Status
Not open for further replies.

solex

Programmer
Joined
Feb 28, 2003
Messages
91
Location
GB
hi, i have got a lot of non fatal mysql errors appearing in my php scripts, they did not show up in my previous host, but are now.
is there a way of turning them off by inserting a line of code ie ignore_user_abort(true); sets ignore user abort on.

thanx inadvance

solex
 
I took it as the errors aren't affecting my code, but the reporting of them is making my page look ugly. In which case you want...


However, my guess is your errors are causing problems with your code you just haven't realized yet... but in the issue of answering your question, just read that link.

-Rob
 
Better yet, figure out why those errors are appearing and fix them.

I am Comptia A+ Certified
 
And the icing on the cake would be to handle errors that might occur because the host is unavailable with a nice page that gives the visitor some custom error page instead of the error message (which is only of interest for the admin).
That page would generate an e-mail to the admin so the condition raises a flag.
 
If the errors were affecting my code I would obviously sort them out! But they are ones like rows not found in a db, and I kneed to know if it couldn’t find one to return no user name.

But thanx for your non snotty help.

SOLEX
 
Well, if you make some query like this:
Code:
$result=mysql_query("SELECT * FROM blabla...",$mysql);
you should allways follow this line with:
Code:
if(mysql_num_rows($result)>0) {
  // some code goes here
}

If your code produces some warnings, it means that the code is badly written and you should fix all these warnings so they will not appear. But if you can't fix this, you can try tu put the @ character in front of the command which should force the warnings and errors not to appear.

But rather try to fix all warnings and errors.
 
The nature of warnings is to alert the creator of the program to a state that is not handled within the code.
If we execute a SQL command that affects no rows it is really not an error. But if we then proceed writing the code based upon the assumption that the result contains something we are causing a Warning/Error when our false assumption later is causing a failure.

I know that it is difficult to anticipate all circumstances, but in terms of quality of the application a basic handling of SQL structures I believe that a result check is a basic necessity.

Some basic checks are:
1. Are we connected?
2. Could the database be selected?
3. Did the SQL execute correctly?
4. If there's a result set, does it contain rows?
5. UPDATE/INSERT/DELETE: how many rows were affected?

When the OIL lamp in your car goes on check whats wrong. Using the @ sign is just like removing the bulb.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top