How to execute mulitple statement SQL queries using $wpdb->query?

TL;DR This is not possible with wpdb. Use dbDelta(). Even better, use something else to run raw queries. Explanation wpdb->query() uses the mysql_query() function. From PHP manual: mysql_query() sends a unique query (multiple queries are not supported) to the currently active database on the server that’s associated with the specified link_identifier. In order for that … Read more

if statement on database query

On your if(), it should be like this: if (!($wpdb->get_row(“SELECT voter_ip FROM ” . $wpdb->prefix . “voter_ips WHERE post_id = $post_id AND voter_ip = ‘$voter_ip'”) Notice the quotation mark added on $voter_ip.

WP database error for comments_popup_link()

Your template code includes $wpdb->print_error(). This function prints the last database error between [ and ] brackets, and the executed SQL code. But if there is no error, you just see the empty brackets and the SQL. $wpdb->show_errors() is used to enable displaying of database errors. If you want to see all database errors, you … Read more