PHP Try and Catch for SQL Insert
Posted
by
meme
on Stack Overflow
See other posts from Stack Overflow
or by meme
Published on 2009-12-16T23:51:57Z
Indexed on
2012/09/07
3:38 UTC
Read the original article
Hit count: 112
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);
...
© Stack Overflow or respective owner