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. 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; } 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 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. 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
Archived
This topic is now archived and is closed to further replies.