wpdb::print_error( string $str = '' ): void|false
- Since
- 0.71
- Source
wp-includes/class-wpdb.php:1799
Compatibility
- WordPress
- since 0.71
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$strstringoptional- The error to display.Default:
''
Return value
void|false- Void if the showing of errors is enabled, false if disabled.
Performance profile
How much work a call to wpdb::print_error() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 11–63
- Plugin surface
- None
- Called by
- 2
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 93.
Nothing here hands control to plugin code.
2 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()one call below wpdb::print_error()
Further down the call graph this can also reach query, option, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 14 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wpdb::print_error() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 11 | none |
| always | 17 | mysqli_error() |
| always | 27–29 | ->get_caller(), sprintf(), error_log() |
| always | 33–35 | mysqli_error(), ->get_caller(), sprintf(), error_log() |
is_multisite() && !defined('ERRORLOGFILE') && !defined('DIEONDBERROR') | 46–48 | ->get_caller(), sprintf(), error_log(), wp_load_translations_early(), is_multisite(), __() |
is_multisite() && !defined('ERRORLOGFILE') && defined('DIEONDBERROR') | 49–51 | ->get_caller(), sprintf(), error_log(), wp_load_translations_early(), is_multisite(), __(), wp_die() |
is_multisite() && defined('ERRORLOGFILE') && !defined('DIEONDBERROR') | 52–54 | ->get_caller(), sprintf(), error_log(), wp_load_translations_early(), is_multisite(), __(), error_log() |
is_multisite() && !defined('ERRORLOGFILE') && !defined('DIEONDBERROR') | 52–54 | mysqli_error(), ->get_caller(), sprintf(), error_log(), wp_load_translations_early(), is_multisite(), __() |
!is_multisite() | 52–54 | ->get_caller(), sprintf(), error_log(), wp_load_translations_early(), is_multisite(), htmlspecialchars(), htmlspecialchars(), __(), printf() |
is_multisite() && defined('ERRORLOGFILE') && defined('DIEONDBERROR') | 55–57 | ->get_caller(), sprintf(), error_log(), wp_load_translations_early(), is_multisite(), __(), error_log(), wp_die() |
is_multisite() && !defined('ERRORLOGFILE') && defined('DIEONDBERROR') | 55–57 | mysqli_error(), ->get_caller(), sprintf(), error_log(), wp_load_translations_early(), is_multisite(), __(), wp_die() |
is_multisite() && defined('ERRORLOGFILE') && !defined('DIEONDBERROR') | 58–60 | mysqli_error(), ->get_caller(), sprintf(), error_log(), wp_load_translations_early(), is_multisite(), __(), error_log() |
2 further outcomes, up to 63 instructions
!is_multisite() | 58–60 | mysqli_error(), ->get_caller(), sprintf(), error_log(), wp_load_translations_early(), is_multisite(), htmlspecialchars(), htmlspecialchars(), __(), printf() |
is_multisite() && defined('ERRORLOGFILE') && defined('DIEONDBERROR') | 61–63 | mysqli_error(), ->get_caller(), sprintf(), error_log(), wp_load_translations_early(), is_multisite(), __(), error_log(), wp_die() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 95 | 11–63 | 7 | 2 more instructions than PHP 8.5 |
| 8.5 | 93 | 11–63 | 7 | |
| 8.4 | 93 | 11–63 | 7 | 1 fewer instruction than PHP 8.3 |
| 8.3 | 94 | 11–64 | 7 | |
| 8.2 | 94 | 11–64 | 7 | |
| 8.1 | 94 | 11–64 | 7 | |
| 7.4 | 94 | 11–64 | 7 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 5
- wp_load_translations_early()Attempts an early load of translations.
- is_multisite()Determines whether Multisite is enabled.
- __()Retrieves the translation of $text.
- wp_die()Kills WordPress execution and displays HTML page with an error message.
- wpdb::get_caller()Retrieves a comma-separated list of the names of the functions that called wpdb.
Used by · 2
- wpdb::get_row()Retrieves one row from the database.
- wpdb::query()Performs a database query, using current database connection.
Source code
public function print_error( $str = '' ) { global $EZSQL_ERROR; if ( ! $str ) { $str = mysqli_error( $this->dbh ); } $EZSQL_ERROR[] = array( 'query' => $this->last_query, 'error_str' => $str, ); if ( $this->suppress_errors ) { return false; } $caller = $this->get_caller(); if ( $caller ) { // Not translated, as this will only appear in the error log. $error_str = sprintf( 'WordPress database error %1$s for query %2$s made by %3$s', $str, $this->last_query, $caller ); } else { $error_str = sprintf( 'WordPress database error %1$s for query %2$s', $str, $this->last_query ); } error_log( $error_str ); // Are we showing errors? if ( ! $this->show_errors ) { return false; } wp_load_translations_early(); // If there is an error then take note of it. if ( is_multisite() ) { $msg = sprintf( "%s [%s]\n%s\n", __( 'WordPress database error:' ), $str, $this->last_query ); if ( defined( 'ERRORLOGFILE' ) ) { error_log( $msg, 3, ERRORLOGFILE ); } if ( defined( 'DIEONDBERROR' ) ) { wp_die( $msg ); } } else { $str = htmlspecialchars( $str, ENT_QUOTES ); $query = htmlspecialchars( $this->last_query, ENT_QUOTES ); printf( '<div id="error"><p class="wpdberror"><strong>%s</strong> [%s]<br /><code>%s</code></p></div>', __( 'WordPress database error:' ), $str, $query ); } }Changelog
Introduced in 0.71. One change between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
void|false to null|false.verified against sourceAbout this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 tag, from
src/wp-includes/class-wpdb.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.