wpdb::query( string $query ): int|bool
- Since
- 0.71
- Source
wp-includes/class-wpdb.php:2214
Description
More information can be found on the documentation page.
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
$querystring- Database query.
Return value
int|bool- Boolean true for CREATE, ALTER, TRUNCATE and DROP queries. Number of rows affected/selected for all other queries. Boolean false on error.
Performance profile
How much work a call to wpdb::query() 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
- Heavy
- Scaling
- Scales with input
- Instructions
- 6–93
- Plugin surface
- 1 hook
- Called by
- 7
Reaches the database via wpdb::query().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 151.
Third-party callbacks on 'query' run inside this call, and their cost is not bounded by anything here.
7 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- sqldatabase query
wpdb::query()this function does it - hookthird-party callbacks
apply_filters()called directly
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 · 129 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wpdb::query() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 6 | none |
| always | 12 | apply_filters() |
!($value instanceof) && !->check_connection() | 37–39 | apply_filters(), ->flush(), ->_do_query(), ->check_connection() |
->check_ascii() && !($value instanceof) && !->check_connection() | 41–43 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), ->check_connection() |
!->check_ascii() && $stripped_query !== false | 42 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), wp_load_translations_early(), __() |
$value instanceof && !->check_connection() | 43–45 | apply_filters(), ->flush(), ->_do_query(), mysqli_errno(), ->check_connection() |
!($value instanceof) && !empty($value) && $mysql_errno !== 2006 | 47–55 | apply_filters(), ->flush(), ->_do_query(), __() |
->check_ascii() && $value instanceof && !->check_connection() | 47–49 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), mysqli_errno(), ->check_connection() |
!($value instanceof) && !empty($value) && $mysql_errno !== 2006 | 48–52 | apply_filters(), ->flush(), ->_do_query(), __(), ->print_error() |
!->check_ascii() && $stripped_query === false && !($value instanceof) && !->check_connection() | 49–51 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), ->check_connection() |
!($value instanceof) && !empty($value) && $mysql_errno !== 2006 && $value instanceof | 50–58 | apply_filters(), ->flush(), ->_do_query(), mysqli_error() |
!($value instanceof) && !empty($value) && $mysql_errno !== 2006 && $value instanceof | 51–55 | apply_filters(), ->flush(), ->_do_query(), mysqli_error(), ->print_error() |
117 further outcomes, up to 93 instructions
->check_ascii() && !($value instanceof) && !empty($value) && $mysql_errno !== 2006 | 51–59 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), __() |
!($value instanceof) && ->check_connection() | 52–62 | apply_filters(), ->flush(), ->_do_query(), ->check_connection(), ->_do_query(), __() |
->check_ascii() && !($value instanceof) && !empty($value) && $mysql_errno !== 2006 | 52–56 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), __(), ->print_error() |
$value instanceof && !empty($value) && $mysql_errno !== 2006 && !($value instanceof) | 53–61 | apply_filters(), ->flush(), ->_do_query(), mysqli_errno(), __() |
!($value instanceof) && ->check_connection() | 53–59 | apply_filters(), ->flush(), ->_do_query(), ->check_connection(), ->_do_query(), __(), ->print_error() |
->check_ascii() && !($value instanceof) && !empty($value) && $mysql_errno !== 2006 && $value instanceof | 54–62 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), mysqli_error() |
$value instanceof && !empty($value) && $mysql_errno !== 2006 && !($value instanceof) | 54–58 | apply_filters(), ->flush(), ->_do_query(), mysqli_errno(), __(), ->print_error() |
!($value instanceof) && ->check_connection() && $value instanceof | 55–65 | apply_filters(), ->flush(), ->_do_query(), ->check_connection(), ->_do_query(), mysqli_error() |
->check_ascii() && !($value instanceof) && !empty($value) && $mysql_errno !== 2006 && $value instanceof | 55–59 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), mysqli_error(), ->print_error() |
!->check_ascii() && $stripped_query === false && $value instanceof && !->check_connection() | 55–57 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), mysqli_errno(), ->check_connection() |
$value instanceof && !empty($value) && $mysql_errno !== 2006 | 56–64 | apply_filters(), ->flush(), ->_do_query(), mysqli_errno(), mysqli_error() |
!($value instanceof) && ->check_connection() && $value instanceof | 56–62 | apply_filters(), ->flush(), ->_do_query(), ->check_connection(), ->_do_query(), mysqli_error(), ->print_error() |
->check_ascii() && !($value instanceof) && ->check_connection() | 56–66 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), ->check_connection(), ->_do_query(), __() |
$value instanceof && !empty($value) && $mysql_errno !== 2006 | 57–61 | apply_filters(), ->flush(), ->_do_query(), mysqli_errno(), mysqli_error(), ->print_error() |
->check_ascii() && $value instanceof && !empty($value) && $mysql_errno !== 2006 && !($value instanceof) | 57–65 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), mysqli_errno(), __() |
->check_ascii() && !($value instanceof) && ->check_connection() | 57–63 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), ->check_connection(), ->_do_query(), __(), ->print_error() |
!($value instanceof) && !empty($value) && $mysql_errno !== 2006 | 58 | apply_filters(), ->flush(), ->_do_query(), __(), mysqli_affected_rows() |
$value instanceof && ->check_connection() && !($value instanceof) | 58–68 | apply_filters(), ->flush(), ->_do_query(), mysqli_errno(), ->check_connection(), ->_do_query(), __() |
->check_ascii() && $value instanceof && !empty($value) && $mysql_errno !== 2006 && !($value instanceof) | 58–62 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), mysqli_errno(), __(), ->print_error() |
->check_ascii() && !($value instanceof) && ->check_connection() && $value instanceof | 59–69 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), ->check_connection(), ->_do_query(), mysqli_error() |
!->check_ascii() && $stripped_query === false && !($value instanceof) && !empty($value) && $mysql_errno !== 2006 | 59–67 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), __() |
$value instanceof && ->check_connection() && !($value instanceof) | 59–65 | apply_filters(), ->flush(), ->_do_query(), mysqli_errno(), ->check_connection(), ->_do_query(), __(), ->print_error() |
->check_ascii() && $value instanceof && !empty($value) && $mysql_errno !== 2006 | 60–68 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), mysqli_errno(), mysqli_error() |
->check_ascii() && !($value instanceof) && ->check_connection() && $value instanceof | 60–66 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), ->check_connection(), ->_do_query(), mysqli_error(), ->print_error() |
!->check_ascii() && $stripped_query === false && !($value instanceof) && !empty($value) && $mysql_errno !== 2006 | 60–64 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), __(), ->print_error() |
!($value instanceof) && !empty($value) && $mysql_errno !== 2006 && $value instanceof | 61 | apply_filters(), ->flush(), ->_do_query(), mysqli_error(), mysqli_affected_rows() |
$value instanceof && ->check_connection() | 61–71 | apply_filters(), ->flush(), ->_do_query(), mysqli_errno(), ->check_connection(), ->_do_query(), mysqli_error() |
->check_ascii() && $value instanceof && !empty($value) && $mysql_errno !== 2006 | 61–65 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), mysqli_errno(), mysqli_error(), ->print_error() |
->check_ascii() && !($value instanceof) && !empty($value) && $mysql_errno !== 2006 | 62 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), __(), mysqli_affected_rows() |
!->check_ascii() && $stripped_query === false && !($value instanceof) && !empty($value) && $mysql_errno !== 2006 && $value instanceof | 62–70 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), mysqli_error() |
$value instanceof && ->check_connection() | 62–68 | apply_filters(), ->flush(), ->_do_query(), mysqli_errno(), ->check_connection(), ->_do_query(), mysqli_error(), ->print_error() |
->check_ascii() && $value instanceof && ->check_connection() && !($value instanceof) | 62–72 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), mysqli_errno(), ->check_connection(), ->_do_query(), __() |
!($value instanceof) && !empty($value) && $mysql_errno !== 2006 && !$query && $value instanceof | 63 | apply_filters(), ->flush(), ->_do_query(), __(), mysqli_fetch_object() |
!($value instanceof) && ->check_connection() | 63–65 | apply_filters(), ->flush(), ->_do_query(), ->check_connection(), ->_do_query(), __(), mysqli_affected_rows() |
!->check_ascii() && $stripped_query === false && !($value instanceof) && !empty($value) && $mysql_errno !== 2006 && $value instanceof | 63–67 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), mysqli_error(), ->print_error() |
->check_ascii() && $value instanceof && ->check_connection() && !($value instanceof) | 63–69 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), mysqli_errno(), ->check_connection(), ->_do_query(), __(), ->print_error() |
$value instanceof && !empty($value) && $mysql_errno !== 2006 && !($value instanceof) | 64 | apply_filters(), ->flush(), ->_do_query(), mysqli_errno(), __(), mysqli_affected_rows() |
!->check_ascii() && $stripped_query === false && !($value instanceof) && ->check_connection() | 64–74 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), ->check_connection(), ->_do_query(), __() |
!($value instanceof) && !empty($value) && $mysql_errno !== 2006 | 65 | apply_filters(), ->flush(), ->_do_query(), __(), mysqli_affected_rows(), mysqli_insert_id() |
->check_ascii() && !($value instanceof) && !empty($value) && $mysql_errno !== 2006 && $value instanceof | 65 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), mysqli_error(), mysqli_affected_rows() |
->check_ascii() && $value instanceof && ->check_connection() | 65–75 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), mysqli_errno(), ->check_connection(), ->_do_query(), mysqli_error() |
!->check_ascii() && $stripped_query === false && $value instanceof && !empty($value) && $mysql_errno !== 2006 && !($value instanceof) | 65–73 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), mysqli_errno(), __() |
!->check_ascii() && $stripped_query === false && !($value instanceof) && ->check_connection() | 65–71 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), ->check_connection(), ->_do_query(), __(), ->print_error() |
!($value instanceof) && !empty($value) && $mysql_errno !== 2006 && $value instanceof && !$query | 66 | apply_filters(), ->flush(), ->_do_query(), mysqli_error(), mysqli_fetch_object() |
!($value instanceof) && ->check_connection() && $value instanceof | 66–68 | apply_filters(), ->flush(), ->_do_query(), ->check_connection(), ->_do_query(), mysqli_error(), mysqli_affected_rows() |
->check_ascii() && $value instanceof && ->check_connection() | 66–72 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), mysqli_errno(), ->check_connection(), ->_do_query(), mysqli_error(), ->print_error() |
!->check_ascii() && $stripped_query === false && $value instanceof && !empty($value) && $mysql_errno !== 2006 && !($value instanceof) | 66–70 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), mysqli_errno(), __(), ->print_error() |
$value instanceof && !empty($value) && $mysql_errno !== 2006 | 67 | apply_filters(), ->flush(), ->_do_query(), mysqli_errno(), mysqli_error(), mysqli_affected_rows() |
->check_ascii() && !($value instanceof) && !empty($value) && $mysql_errno !== 2006 && !$query && $value instanceof | 67 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), __(), mysqli_fetch_object() |
->check_ascii() && !($value instanceof) && ->check_connection() | 67–69 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), ->check_connection(), ->_do_query(), __(), mysqli_affected_rows() |
!->check_ascii() && $stripped_query === false && !($value instanceof) && ->check_connection() && $value instanceof | 67–77 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), ->check_connection(), ->_do_query(), mysqli_error() |
!($value instanceof) && !empty($value) && $mysql_errno !== 2006 && $value instanceof | 68 | apply_filters(), ->flush(), ->_do_query(), mysqli_error(), mysqli_affected_rows(), mysqli_insert_id() |
!($value instanceof) && ->check_connection() && !$query && $value instanceof | 68–70 | apply_filters(), ->flush(), ->_do_query(), ->check_connection(), ->_do_query(), __(), mysqli_fetch_object() |
->check_ascii() && $value instanceof && !empty($value) && $mysql_errno !== 2006 && !($value instanceof) | 68 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), mysqli_errno(), __(), mysqli_affected_rows() |
!->check_ascii() && $stripped_query === false && $value instanceof && !empty($value) && $mysql_errno !== 2006 | 68–76 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), mysqli_errno(), mysqli_error() |
!->check_ascii() && $stripped_query === false && !($value instanceof) && ->check_connection() && $value instanceof | 68–74 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), ->check_connection(), ->_do_query(), mysqli_error(), ->print_error() |
$value instanceof && !empty($value) && $mysql_errno !== 2006 && !($value instanceof) && !$query | 69 | apply_filters(), ->flush(), ->_do_query(), mysqli_errno(), __(), mysqli_fetch_object() |
->check_ascii() && !($value instanceof) && !empty($value) && $mysql_errno !== 2006 | 69 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), __(), mysqli_affected_rows(), mysqli_insert_id() |
$value instanceof && ->check_connection() && !($value instanceof) | 69–71 | apply_filters(), ->flush(), ->_do_query(), mysqli_errno(), ->check_connection(), ->_do_query(), __(), mysqli_affected_rows() |
!->check_ascii() && $stripped_query === false && $value instanceof && !empty($value) && $mysql_errno !== 2006 | 69–73 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), mysqli_errno(), mysqli_error(), ->print_error() |
->check_ascii() && !($value instanceof) && !empty($value) && $mysql_errno !== 2006 && $value instanceof && !$query | 70 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), mysqli_error(), mysqli_fetch_object() |
!($value instanceof) && ->check_connection() | 70–72 | apply_filters(), ->flush(), ->_do_query(), ->check_connection(), ->_do_query(), __(), mysqli_affected_rows(), mysqli_insert_id() |
->check_ascii() && !($value instanceof) && ->check_connection() && $value instanceof | 70–72 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), ->check_connection(), ->_do_query(), mysqli_error(), mysqli_affected_rows() |
!->check_ascii() && $stripped_query === false && !($value instanceof) && !empty($value) && $mysql_errno !== 2006 | 70 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), __(), mysqli_affected_rows() |
!->check_ascii() && $stripped_query === false && $value instanceof && ->check_connection() && !($value instanceof) | 70–80 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), mysqli_errno(), ->check_connection(), ->_do_query(), __() |
!($value instanceof) && ->check_connection() && $value instanceof && !$query | 71–73 | apply_filters(), ->flush(), ->_do_query(), ->check_connection(), ->_do_query(), mysqli_error(), mysqli_fetch_object() |
$value instanceof && !empty($value) && $mysql_errno !== 2006 && !($value instanceof) | 71 | apply_filters(), ->flush(), ->_do_query(), mysqli_errno(), __(), mysqli_affected_rows(), mysqli_insert_id() |
->check_ascii() && $value instanceof && !empty($value) && $mysql_errno !== 2006 | 71 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), mysqli_errno(), mysqli_error(), mysqli_affected_rows() |
!->check_ascii() && $stripped_query === false && $value instanceof && ->check_connection() && !($value instanceof) | 71–77 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), mysqli_errno(), ->check_connection(), ->_do_query(), __(), ->print_error() |
$value instanceof && !empty($value) && $mysql_errno !== 2006 && !$query | 72 | apply_filters(), ->flush(), ->_do_query(), mysqli_errno(), mysqli_error(), mysqli_fetch_object() |
->check_ascii() && !($value instanceof) && !empty($value) && $mysql_errno !== 2006 && $value instanceof | 72 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), mysqli_error(), mysqli_affected_rows(), mysqli_insert_id() |
$value instanceof && ->check_connection() | 72–74 | apply_filters(), ->flush(), ->_do_query(), mysqli_errno(), ->check_connection(), ->_do_query(), mysqli_error(), mysqli_affected_rows() |
->check_ascii() && !($value instanceof) && ->check_connection() && !$query && $value instanceof | 72–74 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), ->check_connection(), ->_do_query(), __(), mysqli_fetch_object() |
->check_ascii() && $value instanceof && !empty($value) && $mysql_errno !== 2006 && !($value instanceof) && !$query | 73 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), mysqli_errno(), __(), mysqli_fetch_object() |
!($value instanceof) && ->check_connection() && $value instanceof | 73–75 | apply_filters(), ->flush(), ->_do_query(), ->check_connection(), ->_do_query(), mysqli_error(), mysqli_affected_rows(), mysqli_insert_id() |
!->check_ascii() && $stripped_query === false && !($value instanceof) && !empty($value) && $mysql_errno !== 2006 && $value instanceof | 73 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), mysqli_error(), mysqli_affected_rows() |
->check_ascii() && $value instanceof && ->check_connection() && !($value instanceof) | 73–75 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), mysqli_errno(), ->check_connection(), ->_do_query(), __(), mysqli_affected_rows() |
!->check_ascii() && $stripped_query === false && $value instanceof && ->check_connection() | 73–83 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), mysqli_errno(), ->check_connection(), ->_do_query(), mysqli_error() |
$value instanceof && !empty($value) && $mysql_errno !== 2006 | 74 | apply_filters(), ->flush(), ->_do_query(), mysqli_errno(), mysqli_error(), mysqli_affected_rows(), mysqli_insert_id() |
$value instanceof && ->check_connection() && !($value instanceof) && !$query | 74–76 | apply_filters(), ->flush(), ->_do_query(), mysqli_errno(), ->check_connection(), ->_do_query(), __(), mysqli_fetch_object() |
->check_ascii() && !($value instanceof) && ->check_connection() | 74–76 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), ->check_connection(), ->_do_query(), __(), mysqli_affected_rows(), mysqli_insert_id() |
!->check_ascii() && $stripped_query === false && $value instanceof && ->check_connection() | 74–80 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), mysqli_errno(), ->check_connection(), ->_do_query(), mysqli_error(), ->print_error() |
->check_ascii() && !($value instanceof) && ->check_connection() && $value instanceof && !$query | 75–77 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), ->check_connection(), ->_do_query(), mysqli_error(), mysqli_fetch_object() |
->check_ascii() && $value instanceof && !empty($value) && $mysql_errno !== 2006 && !($value instanceof) | 75 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), mysqli_errno(), __(), mysqli_affected_rows(), mysqli_insert_id() |
!->check_ascii() && $stripped_query === false && !($value instanceof) && !empty($value) && $mysql_errno !== 2006 && !$query && $value instanceof | 75 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), __(), mysqli_fetch_object() |
!->check_ascii() && $stripped_query === false && !($value instanceof) && ->check_connection() | 75–77 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), ->check_connection(), ->_do_query(), __(), mysqli_affected_rows() |
->check_ascii() && $value instanceof && !empty($value) && $mysql_errno !== 2006 && !$query | 76 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), mysqli_errno(), mysqli_error(), mysqli_fetch_object() |
$value instanceof && ->check_connection() && !($value instanceof) | 76–78 | apply_filters(), ->flush(), ->_do_query(), mysqli_errno(), ->check_connection(), ->_do_query(), __(), mysqli_affected_rows(), mysqli_insert_id() |
->check_ascii() && $value instanceof && ->check_connection() | 76–78 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), mysqli_errno(), ->check_connection(), ->_do_query(), mysqli_error(), mysqli_affected_rows() |
!->check_ascii() && $stripped_query === false && $value instanceof && !empty($value) && $mysql_errno !== 2006 && !($value instanceof) | 76 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), mysqli_errno(), __(), mysqli_affected_rows() |
$value instanceof && ->check_connection() && !$query | 77–79 | apply_filters(), ->flush(), ->_do_query(), mysqli_errno(), ->check_connection(), ->_do_query(), mysqli_error(), mysqli_fetch_object() |
->check_ascii() && !($value instanceof) && ->check_connection() && $value instanceof | 77–79 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), ->check_connection(), ->_do_query(), mysqli_error(), mysqli_affected_rows(), mysqli_insert_id() |
!->check_ascii() && $stripped_query === false && !($value instanceof) && !empty($value) && $mysql_errno !== 2006 | 77 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), __(), mysqli_affected_rows(), mysqli_insert_id() |
->check_ascii() && $value instanceof && !empty($value) && $mysql_errno !== 2006 | 78 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), mysqli_errno(), mysqli_error(), mysqli_affected_rows(), mysqli_insert_id() |
!->check_ascii() && $stripped_query === false && !($value instanceof) && !empty($value) && $mysql_errno !== 2006 && $value instanceof && !$query | 78 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), mysqli_error(), mysqli_fetch_object() |
->check_ascii() && $value instanceof && ->check_connection() && !($value instanceof) && !$query | 78–80 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), mysqli_errno(), ->check_connection(), ->_do_query(), __(), mysqli_fetch_object() |
!->check_ascii() && $stripped_query === false && !($value instanceof) && ->check_connection() && $value instanceof | 78–80 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), ->check_connection(), ->_do_query(), mysqli_error(), mysqli_affected_rows() |
$value instanceof && ->check_connection() | 79–81 | apply_filters(), ->flush(), ->_do_query(), mysqli_errno(), ->check_connection(), ->_do_query(), mysqli_error(), mysqli_affected_rows(), mysqli_insert_id() |
!->check_ascii() && $stripped_query === false && $value instanceof && !empty($value) && $mysql_errno !== 2006 | 79 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), mysqli_errno(), mysqli_error(), mysqli_affected_rows() |
!->check_ascii() && $stripped_query === false && !($value instanceof) && !empty($value) && $mysql_errno !== 2006 && $value instanceof | 80 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), mysqli_error(), mysqli_affected_rows(), mysqli_insert_id() |
->check_ascii() && $value instanceof && ->check_connection() && !($value instanceof) | 80–82 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), mysqli_errno(), ->check_connection(), ->_do_query(), __(), mysqli_affected_rows(), mysqli_insert_id() |
!->check_ascii() && $stripped_query === false && !($value instanceof) && ->check_connection() && !$query && $value instanceof | 80–82 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), ->check_connection(), ->_do_query(), __(), mysqli_fetch_object() |
->check_ascii() && $value instanceof && ->check_connection() && !$query | 81–83 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), mysqli_errno(), ->check_connection(), ->_do_query(), mysqli_error(), mysqli_fetch_object() |
!->check_ascii() && $stripped_query === false && $value instanceof && !empty($value) && $mysql_errno !== 2006 && !($value instanceof) && !$query | 81 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), mysqli_errno(), __(), mysqli_fetch_object() |
!->check_ascii() && $stripped_query === false && $value instanceof && ->check_connection() && !($value instanceof) | 81–83 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), mysqli_errno(), ->check_connection(), ->_do_query(), __(), mysqli_affected_rows() |
!->check_ascii() && $stripped_query === false && !($value instanceof) && ->check_connection() | 82–84 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), ->check_connection(), ->_do_query(), __(), mysqli_affected_rows(), mysqli_insert_id() |
->check_ascii() && $value instanceof && ->check_connection() | 83–85 | apply_filters(), ->flush(), ->check_ascii(), ->_do_query(), mysqli_errno(), ->check_connection(), ->_do_query(), mysqli_error(), mysqli_affected_rows(), mysqli_insert_id() |
!->check_ascii() && $stripped_query === false && !($value instanceof) && ->check_connection() && $value instanceof && !$query | 83–85 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), ->check_connection(), ->_do_query(), mysqli_error(), mysqli_fetch_object() |
!->check_ascii() && $stripped_query === false && $value instanceof && !empty($value) && $mysql_errno !== 2006 && !($value instanceof) | 83 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), mysqli_errno(), __(), mysqli_affected_rows(), mysqli_insert_id() |
!->check_ascii() && $stripped_query === false && $value instanceof && !empty($value) && $mysql_errno !== 2006 && !$query | 84 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), mysqli_errno(), mysqli_error(), mysqli_fetch_object() |
!->check_ascii() && $stripped_query === false && $value instanceof && ->check_connection() | 84–86 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), mysqli_errno(), ->check_connection(), ->_do_query(), mysqli_error(), mysqli_affected_rows() |
!->check_ascii() && $stripped_query === false && !($value instanceof) && ->check_connection() && $value instanceof | 85–87 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), ->check_connection(), ->_do_query(), mysqli_error(), mysqli_affected_rows(), mysqli_insert_id() |
!->check_ascii() && $stripped_query === false && $value instanceof && !empty($value) && $mysql_errno !== 2006 | 86 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), mysqli_errno(), mysqli_error(), mysqli_affected_rows(), mysqli_insert_id() |
!->check_ascii() && $stripped_query === false && $value instanceof && ->check_connection() && !($value instanceof) && !$query | 86–88 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), mysqli_errno(), ->check_connection(), ->_do_query(), __(), mysqli_fetch_object() |
!->check_ascii() && $stripped_query === false && $value instanceof && ->check_connection() && !($value instanceof) | 88–90 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), mysqli_errno(), ->check_connection(), ->_do_query(), __(), mysqli_affected_rows(), mysqli_insert_id() |
!->check_ascii() && $stripped_query === false && $value instanceof && ->check_connection() && !$query | 89–91 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), mysqli_errno(), ->check_connection(), ->_do_query(), mysqli_error(), mysqli_fetch_object() |
!->check_ascii() && $stripped_query === false && $value instanceof && ->check_connection() | 91–93 | apply_filters(), ->flush(), ->check_ascii(), ->strip_invalid_text_from_query(), ->flush(), ->_do_query(), mysqli_errno(), ->check_connection(), ->_do_query(), mysqli_error(), mysqli_affected_rows(), mysqli_insert_id() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 151 | 6–93 | 18 | |
| 8.5 | 151 | 6–93 | 18 | |
| 8.4 | 151 | 6–93 | 18 | 12 fewer instructions than PHP 8.3 |
| 8.3 | 163 | 6–102 | 18 | |
| 8.2 | 163 | 6–102 | 18 | 1 more instruction than PHP 8.1 |
| 8.1 | 162 | 6–102 | 18 | |
| 7.4 | 162 | 6–102 | 18 |
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.
Hooks and filters fired · 1
One hook fires while wpdb::query() runs, in this order:
Uses · 9
- apply_filters()Calls the callback functions that have been added to a filter hook.
- wp_load_translations_early()Attempts an early load of translations.
- __()Retrieves the translation of $text.
- wpdb::flush()Kills cached query results.
- wpdb::check_ascii()Checks if a string is ASCII.
- wpdb::strip_invalid_text_from_query()Strips any invalid characters from the query.
- wpdb::_do_query()Internal function to perform the mysqli_query() call.
- wpdb::check_connection()Checks that the connection to the database is still up. If not, try to reconnect.
- wpdb::print_error()Prints SQL/DB error.
Used by · 7
- wpdb::_insert_replace_helper()Helper function for insert and replace.
- wpdb::delete()Deletes a row in the table.
- wpdb::get_col()Retrieves one column from the database.
- wpdb::get_results()Retrieves an entire SQL result set from the database (i.e., many rows).
- wpdb::get_row()Retrieves one row from the database.
- wpdb::get_var()Retrieves one value from the database.
- wpdb::update()Updates a row in the table.
Source code
public function query( $query ) { if ( ! $this->ready ) { $this->check_current_query = true; return false; } /** * Filters the database query. * * Some queries are made before the plugins have been loaded, * and thus cannot be filtered with this method. * * @since 2.1.0 * * @param string $query Database query. */ $query = apply_filters( 'query', $query ); if ( ! $query ) { $this->insert_id = 0; return false; } $this->flush(); // Log how the function was called. $this->func_call = "\$db->query(\"$query\")"; // If we're writing to the database, make sure the query will write safely. if ( $this->check_current_query && ! $this->check_ascii( $query ) ) { $stripped_query = $this->strip_invalid_text_from_query( $query ); /* * strip_invalid_text_from_query() can perform queries, so we need * to flush again, just to make sure everything is clear. */ $this->flush(); if ( $stripped_query !== $query ) { $this->insert_id = 0; $this->last_query = $query; wp_load_translations_early(); $this->last_error = __( 'WordPress database error: Could not perform query because it contains invalid data.' ); return false; } } $this->check_current_query = true; // Keep track of the last query for debug. $this->last_query = $query; $this->_do_query( $query ); // Database server has gone away, try to reconnect. $mysql_errno = 0; if ( $this->dbh instanceof mysqli ) { $mysql_errno = mysqli_errno( $this->dbh ); } else { /* * $dbh is defined, but isn't a real connection. * Something has gone horribly wrong, let's try a reconnect. */ $mysql_errno = 2006; } if ( empty( $this->dbh ) || 2006 === $mysql_errno ) { if ( $this->check_connection() ) { $this->_do_query( $query ); } else { $this->insert_id = 0; return false; } } // If there is an error then take note of it. if ( $this->dbh instanceof mysqli ) { $this->last_error = mysqli_error( $this->dbh );Changelog
Introduced in 0.71. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 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.