|
Posted by Jerry Stuckle on 12/16/09 11:59
Klaus Brune wrote:
> In article <1159199002.996276.77090@i42g2000cwa.googlegroups.com>,
> mcyi2mr3@googlemail.com says...
>
>>Hi all!
>>
>>How can you get rid of the error that displays if you do a query which
>>returns no result and then try and fetch the array, WITHOUT having to
>>put the while in another conditional like if ($result != ''), something
>>more efficient if possible.
>>
>>regards
>>
>>Marc
>>
>>
> I don't know if this will be more efficient than using a conditional,
> but two other avenues, off the top of my head...
>
> 1) Turn off error messages, then enable again after your call. Something
> like...
>
> $oldErrorReporting = error_reporting(0)
>
> // ... do your stuff ...
>
> error_reporting($oldErrorReporting)
>
>
> 2) Do output buffering before and after your code to grab any unwanted
> errors, notification, etc...
>
> ob_start();
> $oldErrorReporting = error_reporting(E_ALL);
> $oldHtmlErrors = ini_set('html_errors',0);
>
> // ... do your stuff ...
>
> $errorMessages = ob_get_clean();
> error_reporting($oldErrorReporting);
> ini_set('html_errors',$oldHtmlErrors);
>
> if(trim($errorMessages) == '') {
> mail('me@example.com','MySQL Error Report',$errorMessages)
> }
>
>
> Hmmm, this might be worthy of a wiki topic. Plus it might be a little
> clearer with syntax highlighting. And I won't have to post multiple
> times if I want to expand the whole error trapping idea when I have
> time. The ideas are flowing already... dumping to different error log
> files based on what routine(s) you're watching for instance. Anyway,
> here's the link...
>
> http://www.gunthersoft.com/wiki/ErrorHandlingWithPHP
>
>
(top posting fixed)
Much less efficient. When you get the error, the MySQL libraries have
to report it back to PHP, and PHP must handle the error. This may (and
generally does) have significant overhead - like logging the error,
determining if it can be handled or the script must be terminated, etc.
A conditional is just a quick test.
You should never plan on getting errors in your code and handling them
like you're suggesting. If for no other reason than a new release may
change the default error handling.
And BTW - please don't top post. Thanks.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|