Query Custom Data in WordPress

If you want to query for custom data in WordPress, you can use

global $wpdb;
$tablename = $wpdb->prefix . 'my_table';
$sql = $wpdb->prepare( "SELECT * FROM {$tablename} WHERE id = %d", $id );
$result = $wpdb->get_results( $sql );

You will get an array containing your objects (in this case, because filtered by ID, only one object).

If you expect only one result, a better way would be:

global $wpdb;
$tablename = $wpdb->prefix . 'my_table';
$sql = $wpdb->prepare( "SELECT * FROM {$tablename} WHERE id = %d", $id );
$result = $wpdb->get_row( $sql );

By using get_row() instead of get_results(), you will directly get the object (without the containing array).