Showing errors with $wpdb update

I would recommend running the following code right after your query to see what’s happening:

exit( var_dump( $wpdb->last_query ) );

This should print the last query that hit your database. In cases like these, I usually will manually run such a query through phpMyAdmin to see if it runs without errors and to see if it even affects the database. Additionally, by seeing the query that was actually run, you may find problems in the query that results from your code. For instance, the query may not return any MySQL errors, but it could run a query that is different than you expect it to be. With this debug code, you’ll at least be able to see what it is and continue on the wonderful debug trail! Furthermore, you may want to explore more of the “Class Variables” (Codex Ref) for $wpdb as they may help further troubleshoot your issue.

Leave a Comment