Why does this Wordpress code throw an empty WPDB error?

I am writing a plugin to read plugins for Wordpress . I see a DB error that I cannot understand. First, I will create a user_entries table . Then I put the sample in this table . When I try to delete a record , I get a very strange error in my debug log. As long as there are no foreign keys, there are no indices on db, etc.

[02-May-2012 11:21:52] WordPress database error for the DELETE FROM request wp_wprss_user_entries
      WHERE owner_uid = 2 AND feed_id = 2; made by do_action, call_user_func_array, wprss_unsubscribe_feed, WprssFeeds-> remove

So what is the mistake? It’s just empty. This doesn't look like complex SQL, and it works fine in the phpmysql query window. I'm not sure what to do for the next step now, and I would like people to be able to unsubscribe from the feed!

+3
source share
2 answers

I thought! $wpdb->print_error()prints this error line even if there is no error. So you should explicitly check if the query returns false - not 0.

    if(false === $wpdb->query($sql)){
      $resp->uf_error = $wpdb->print_error();
    }
+7
source

Try compiling your query, so it only tries to remove from the WHERE clause ..

those.:

DELETE FROM wp_wprss_user_entries WHERE owner_uid=2;
run query
DELETE FROM wp_wprss_user_entries WHERE feed_id=2;
run query

M

-2
source

All Articles