1

my friends.

I'm creating a custom php page on my wordpress website where I need to read and update a custom table. I'm using $wpdb class but I get no result when I use the table I create (the $result value stays null). With wordpress tables, it works fine and return the results. The problem is how to use my table...

This is everything that I tryed (the table name is wp_test):
$result = $wpdb->get_results("SELECT test_id, test_cli, test_URL FROM {$wpdb->wp_test}");

$result = $wpdb->get_results("SELECT test_id, test_cli, test_URL FROM {$wpdb->test}");

$result = $wpdb->get_results("SELECT test_id, test_cli, test_URL FROM $wpdb->wp_test");

$result = $wpdb->get_results("SELECT test_id, test_cli, test_URL FROM ``wp_test``"); (with only one backticks)

$result = $wpdb->get_results("SELECT test_id, test_cli, test_URL FROM wp_test");

If I use a wordpress table, it returns the values:
$result = $wpdb->get_results( "SELECT * FROM {$wpdb->posts} LIMIT 10" );

Please, can you help me?
Thanks!

1
  • Show full code with where you tried? Commented Nov 12, 2021 at 7:11

1 Answer 1

0

The best way to debug the issue is to print the raw SQL on the front and then run the query manually copying and pasting to the MySQL console.

Or you can try logging the last DB error with the below snippet.

$wpdb->suppress_errors(false); // execute query here if($wpdb->last_error !== '') : $wpdb->print_error(); endif; 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.