$wpdb table name

I’m having problem with getting data from database via $wpdb:

function nadji_sve_statuse() {
  global $wpdb, $leaguemanager;
  $league = $leaguemanager->getCurrentLeague();

  $svi_statusi = $wpdb->get_var( "SELECT * FROM {$wpdb->leaguemanager_person_status} WHERE 1" );
  
  return $svi_statusi;
 }

When I replace {$wpdb->leaguemanager_person_status} with full and real table name wp_leaguemanager_person_status, it works fine – but when user tries to rename database table prefixes to something other, a new problem will surface. What am I doing wrong?

Related posts

Leave a Reply

1 comment

  1. You should get the prefix of the table, try this:

    function nadji_sve_statuse() {
      global $wpdb, $leaguemanager;
      $league = $leaguemanager->getCurrentLeague();
      $tableName = $wpdb->prefix . 'leaguemanager_person_status';
    
      $svi_statusi = $wpdb->get_var( "SELECT * FROM {$tableName} WHERE 1" );
    
      return $svi_statusi;
     }