wpdb::get_row()
Retrieves one row from the database.
Executes a SQL query and returns the row from the SQL result.
Method of the class: wpdb{}
Uses: wpdb::query()
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.
Examples
#1 Get all the information about link 10
$mylink = $wpdb->get_row( "SELECT * FROM $wpdb->links WHERE link_id = 10" ); // Now, the properties (variables) of $mylink are names // columns from the table $wpdb->links with the values of the table fields: echo $mylink->link_id; // display "10"
#2 Using a constant:
$mylink = $wpdb->get_row( "SELECT * FROM $wpdb->links WHERE link_id = 10", ARRAY_A ); // the result will be an associative array echo $mylink['link_id']; // display "10"
or
$mylink = $wpdb->get_row( "SELECT * FROM $wpdb->links WHERE link_id = 10", ARRAY_N ); // the result will be a numbered array echo $mylink[1]; // display "10"
Changelog
Since 0.71 | Introduced. |