1

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?

1

1 Answer 1

6

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; } 
Sign up to request clarification or add additional context in comments.

1 Comment

I recommend you to use backtics surrounding table name "SELECT * FROM `{$tableName}` WHERE 1"

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.