Get error messages when $wpdb->insert() returns false?

$wpdb->insert() method returns false if the row could not be inserted. Otherwise, it returns the number of affected rows (which will always be 1).

You can turn error echoing on and off with the show_errors and hide_errors, respectively.

<?php $wpdb->show_errors(); ?> 
<?php $wpdb->hide_errors(); ?> 

You can also print the error (if any) generated by the most recent query with print_error.

<?php $wpdb->print_error(); ?> 

You can also use $last_error field, which will contain the most recent error text generated by MySQL.

Leave a Comment