On this page
wpdb::bail( string $message, string $error_code = '500' ): void|false
Wraps errors in a nice header and footer and dies.
Description
Will not die if wpdb::$show_errors is false.
Parameters
$messagestring Required-
The error message.
$error_codestring Optional-
A computer-readable string to identify the error.
Default'500'.Default:
'500'
Return
void|false Void if the showing of errors is enabled, false if disabled.
Source
File: wp-includes/class-wpdb.php. View all references
public function bail( $message, $error_code = '500' ) {
if ( $this->show_errors ) {
$error = '';
if ( $this->use_mysqli ) {
if ( $this->dbh instanceof mysqli ) {
$error = mysqli_error( $this->dbh );
} elseif ( mysqli_connect_errno() ) {
$error = mysqli_connect_error();
}
} else {
if ( is_resource( $this->dbh ) ) {
$error = mysql_error( $this->dbh );
} else {
$error = mysql_error();
}
}
if ( $error ) {
$message = '<p><code>' . $error . "</code></p>\n" . $message;
}
wp_die( $message );
} else {
if ( class_exists( 'WP_Error', false ) ) {
$this->error = new WP_Error( $error_code, $message );
} else {
$this->error = $message;
}
return false;
}
}
Related
Uses
| Uses | Description |
|---|---|
| wp_die() wp-includes/functions.php | Kills WordPress execution and displays HTML page with an error message. |
| WP_Error::__construct() wp-includes/class-wp-error.php | Initializes the error. |
Used By
| Used By | Description |
|---|---|
| wpdb::check_connection() wp-includes/class-wpdb.php | Checks that the connection to the database is still up. If not, try to reconnect. |
| wpdb::select() wp-includes/class-wpdb.php | Selects a database using the current or provided database connection. |
| wpdb::db_connect() wp-includes/class-wpdb.php | Connects to and selects database. |
Changelog
| Version | Description |
|---|---|
| 1.5.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wpdb/bail