I have a page on my website (high traffic) that does an insert on every page load.
I am curious of the fastest and safest way to (catch an error) and continue if the system is not able to do the insert into MySQL. Should I use try/catch or die or something else. I want to make sure the insert happens but if for some reason it can't I want the page to continue to load anyway.
...
$db = mysql_select_db('mobile', $conn);
mysql_query("INSERT INTO redirects SET ua_string = '$ua_string'") or die('Error #10');
mysql_close($conn);
...
Use any method described in the previous post to somehow catch the mysql error.
Most common is:
This would also work:
try { ... } catch {Exception $e) { .... }
will not work!Note: Not directly related to you question but I think it would much more better if you display something usefull to the user. I would never revisit a website that just displays a blank screen or any mysterious error message.
if you want to log the error etc you should use try/catch, if you dont; just put @ before mysql_query
edit : you can use try catch like this; so you can log the error and let the page continue to load
if error occurs, you will get something like this->
with status code:409.