On this page
wpdb::get_row( string|null $query = null, string $output = OBJECT, int $y ): array|object|null|void
Retrieves one row from the database.
Description
Executes a SQL query and returns the row from the SQL result.
Parameters
$querystring|null Optional-
SQL query.
Default:
null $outputstring Optional-
The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to an stdClass object, an associative array, or a numeric array, respectively.
Default:
OBJECT $yint Optional-
Row to return. Indexed from 0.
Return
array|object|null|void Database query result in format specified by $output or null on failure.
Source
File: wp-includes/class-wpdb.php. View all references
public function get_row( $query = null, $output = OBJECT, $y = 0 ) {
$this->func_call = "\$db->get_row(\"$query\",$output,$y)";
if ( $query ) {
if ( $this->check_current_query && $this->check_safe_collation( $query ) ) {
$this->check_current_query = false;
}
$this->query( $query );
} else {
return null;
}
if ( ! isset( $this->last_result[ $y ] ) ) {
return null;
}
if ( OBJECT === $output ) {
return $this->last_result[ $y ] ? $this->last_result[ $y ] : null;
} elseif ( ARRAY_A === $output ) {
return $this->last_result[ $y ] ? get_object_vars( $this->last_result[ $y ] ) : null;
} elseif ( ARRAY_N === $output ) {
return $this->last_result[ $y ] ? array_values( get_object_vars( $this->last_result[ $y ] ) ) : null;
} elseif ( OBJECT === strtoupper( $output ) ) {
// Back compat for OBJECT being previously case-insensitive.
return $this->last_result[ $y ] ? $this->last_result[ $y ] : null;
} else {
$this->print_error( ' $db->get_row(string query, output type, int offset) -- Output type must be one of: OBJECT, ARRAY_A, ARRAY_N' );
}
}
Related
Uses
| Uses | Description |
|---|---|
| wpdb::check_safe_collation() wp-includes/class-wpdb.php | Checks if the query is accessing a collation considered safe on the current version of MySQL. |
| wpdb::query() wp-includes/class-wpdb.php | Performs a database query, using current database connection. |
| wpdb::print_error() wp-includes/class-wpdb.php | Prints SQL/DB error. |
Used By
| Used By | Description |
|---|---|
| WP_Debug_Data::get_mysql_var() wp-admin/includes/class-wp-debug-data.php | Returns the value of a MySQL system variable. |
| wp_delete_attachment_files() wp-includes/post.php | Deletes all files that belong to the given attachment. |
| WP_Site::get_instance() wp-includes/class-wp-site.php | Retrieves a site from the database by its ID. |
| WP_Network::get_instance() wp-includes/class-wp-network.php | Retrieves a network from the database by its ID. |
| WP_Comment::get_instance() wp-includes/class-wp-comment.php | Retrieves a WP_Comment instance. |
| delete_network_option() wp-includes/option.php | Removes a network option by name. |
| get_network_option() wp-includes/option.php | Retrieves a network’s option value based on the option name. |
| wpdb::strip_invalid_text() wp-includes/class-wpdb.php | Strips any invalid characters based on value/charset pairs. |
| maybe_convert_table_to_utf8mb4() wp-admin/includes/upgrade.php | If a table only contains utf8 or utf8mb4 columns, convert it to utf8mb4. |
| allow_subdirectory_install() wp-admin/includes/network.php | Allow subdirectory installation. |
| WP_User::get_data_by() wp-includes/class-wp-user.php | Returns only the main user fields. |
| get_calendar() wp-includes/general-template.php | Displays calendar with days that have posts as links. |
| delete_usermeta() wp-includes/deprecated.php | Remove user meta data. |
| update_usermeta() wp-includes/deprecated.php | Update metadata of user. |
| wp_insert_term() wp-includes/taxonomy.php | Adds a new term to the database. |
| delete_option() wp-includes/option.php | Removes option by name. Prevents removal of protected WordPress options. |
| get_option() wp-includes/option.php | Retrieves an option value based on an option name. |
| count_users() wp-includes/user.php | Counts number of users who have each of the user roles. |
| WP_Post::get_instance() wp-includes/class-wp-post.php | Retrieve WP_Post instance. |
| wp_delete_attachment() wp-includes/post.php | Trashes or deletes an attachment. |
| wp_delete_post() wp-includes/post.php | Trashes or deletes a post or page. |
| get_most_recent_post_of_user() wp-includes/ms-functions.php | Gets a user’s most recent post. |
| wpmu_activate_signup() wp-includes/ms-functions.php | Activates a signup. |
| wpmu_validate_user_signup() wp-includes/ms-functions.php | Sanitizes and validates data required for a user sign-up. |
| wpmu_validate_blog_signup() wp-includes/ms-functions.php | Processes new site registrations. |
| get_bookmark() wp-includes/bookmark.php | Retrieves bookmark data. |
| get_blog_details() wp-includes/ms-blogs.php | Retrieve the details for a blog from the blogs table and blog options. |
| get_metadata_by_mid() wp-includes/meta.php | Retrieves metadata by meta ID. |
Changelog
| Version | Description |
|---|---|
| 0.71 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wpdb/get_row