Jump to content

PHP mysql_query() or custom_funtion()


peterjc

Recommended Posts

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

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;
}

 

 

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.