How to get last updated row or ID in wordpress.
Like : $wpdb->insert_id;
I had the same problem.
There is no equivalent function.
$wpdb->insert_id
works only after$wpdb->insert
Alternative way
If it's an update, you can either get the id with a query based on the data you have got, or most of the time, you should have already got the id before update it.
global $wpdb;
$data = array(
'first_name' => "John",
'last_name' => "Doe"
);
$where = array(
'id' => $my_id
);
$res_update = $wpdb->update( $wpdb->prefix . "my_table", $data, $where );
if( $res_update === false ){
error_log( 'my error');
}
return $my_id;
Once again select the same row updated on success.
if($wpdb->last_error !== '') {
//throw error stuffs
}else{
$last_updated_row = $wpdb->get_row("SELECT * FROM $wpdb->prefix . 'my_table' WHERE id = $my_id");
}
$this->db->affected_rows
that type in wordpress get the last affected_rows. It passable?.