Support » Fixing WordPress » Basic wpdb query not working; no results

  • Resolved ixwa

    (@ixwa)


    global $wpdb;
    $gallery = $wpdb->get_row("SELECT * FROM $wpdb->wp_ngg_gallery WHERE gid = 3");
    echo $gallery->slug;

    Why doesn’t this work? Isn’t this the most rudimentary type of wpdb query statement? I should be getting results (checked the table/column names in phpmyadmin). I also checked if $gallery exists after and it comes back negative.

    Tried get_var, get_results too–nada.

    Huh???

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter ixwa

    (@ixwa)

    Interestingly, using a standard WP table like wp_links works.

    Does anyone know if the NextGen gallery mySQL tables are somehow permission-based?? That is just weird.

    Thread Starter ixwa

    (@ixwa)

    If you want something done properly DO IT YOURSELF.

    For anyone who encountered this same behavior, behold the simple, stupid answer: The wordpress codex example ONLY works for WP-specific tables. Any other types of tables created by plugins or yourself use the basic mySQL syntax format:

    $mystuff = $wpdb->get_row("SELECT * FROM my_table_name WHERE something = something");

    No $wpdb->table_name, no prefix junk, and no concatenated PHP strings.

    Be careful what you read in the codex…it’s not all there.

    Thanks so much..! I’ve got the same problem and solved it as what you did. I feel so stupid after spending 2hrs fixing the bug…

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Basic wpdb query not working; no results’ is closed to new replies.