peterjc Posted August 14, 2012 Share Posted August 14, 2012 Usually we would use mysql_query($sql) or trigger_error(mysql_error()); So instead of using trigger_error() directly, could i use our own function like below? mysql_query($sql) or showError(); function showError() { trigger_error(mysql_error()); die(); } The purpose is i want to end the script if errors were found. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/267047-php-mysql_query-or-custom_funtion/ Share on other sites More sharing options...
jazzman1 Posted August 14, 2012 Share Posted August 14, 2012 Yes, you can, but does not make sense b/s it will show you only one error -> mysql_error(). You have to use functions to show you multiple errors, for example mysqli_connect error number or something else.. mysql_query($sql) or showError(mysqli_connect_errno()); function showError($error = null) { trigger_error($error); exit; } Quote Link to comment https://forums.phpfreaks.com/topic/267047-php-mysql_query-or-custom_funtion/#findComment-1369228 Share on other sites More sharing options...
peterjc Posted August 14, 2012 Author Share Posted August 14, 2012 Thanks for that jazzman1. By the way, i don't really know how the "or" statement work. Example: We usually use: mysql_query($sql) or trigger_error() and so on could we actually use it for our own function as well? Example own_function() or trigger_error(); Thanks Quote Link to comment https://forums.phpfreaks.com/topic/267047-php-mysql_query-or-custom_funtion/#findComment-1369253 Share on other sites More sharing options...
Christian F. Posted August 14, 2012 Share Posted August 14, 2012 The custom function is quite unnecessary, especially if you take a second look at the PHP manual for trigger_error (): It's perfectly capable of halting further execution of the script on its own. Quote Link to comment https://forums.phpfreaks.com/topic/267047-php-mysql_query-or-custom_funtion/#findComment-1369301 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.