wpdb::get_row() public WP 0.71
Retrieves one row from the database.
Executes a SQL query and returns the row from the SQL result.
{} It's a method of the class: wpdb{}
No Hooks.
Return
Array/Object/null/null. Database query result in format specified by $output or null on failure.
Usage
global $wpdb; $wpdb->get_row( $query, $output, $y );
- $query(string/null)
- SQL query.
Default: null - $output(string)
- 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 - $y(int)
- Row to return. Indexed from 0.
Default: 0
Changelog
Since 0.71 | Introduced. |
Code of wpdb::get_row() wpdb::get row WP 5.6
public function get_row( $query = null, $output = OBJECT, $y = 0 ) {
$this->func_call = "\$db->get_row(\"$query\",$output,$y)";
if ( $this->check_current_query && $this->check_safe_collation( $query ) ) {
$this->check_current_query = false;
}
if ( $query ) {
$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' );
}
}