0

I am making a database request in wordpress to make this question: select * from tc_chat_clt;

How ever a error appears, what am I doing wrong?

$users = $wpdb->get_results($wpdb->prepare('SELECT * FROM %s',`tc_chat_clt`));
1

PHP views backticks (ie, ``) as delimiting something that should be executed, not as a quotation character. Use single quotes (') instead.

$users = $wpdb->get_results($wpdb->prepare('SELECT * FROM %s', 'tc_chat_clt'));
4
  • Thanks for answering, like I had posted the error appears like this: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '''' at line 1] SELECT * FROM '' Dec 13 '20 at 2:37
  • and if I use this cotes ' , firstly I was using them the error says this : [You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''tc_chat_clt'' at line 1] SELECT * FROM 'tc_chat_clt' Dec 13 '20 at 2:38
  • if I use $wpdb->get_results('SELECT * FROM tc_chat_clt'); the code goes well; but I think it is better to use prepare(); Dec 13 '20 at 2:40
  • 1
    ->prepare() isn't strictly necessary in this specific case, because you're not passing it any variables. But using ->prepare() is a good habit to cultivate.
    – Pat J
    Dec 13 '20 at 2:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.