Quantcast
Channel: Question and Answer » wpdb
Viewing all articles
Browse latest Browse all 44

$wpdb->last_error deosn't show the query on error

$
0
0

I am inserting data in the custom table using the $wpdb->insert. However, upon error I don’t seem to get any information from $wpdb->last_error. What could be the cause of this?

I already have this configuration set in wp-config

define('WP_DEBUG', false);
define('SAVEQUERIES', true);

The code is as below:

$result = $wpdb->insert($this->table, $data_);
if (false === $result) {
   error_log($wpdb->last_error);
}

$this->table and $data_ are populated correctly as it runs successfully.
But I don’t seem to get any information on the query that is failed. Is there any way I can get the actual query ran in $wpdb->insert?

Solution

OK so I figured out the problem. Insert query was failing because one of the column data was huge and exceeding the column size of the database. The column was varchar(500) but the actual data was more then 500 characters, thus failing the query. I changed the column to TEXT and insert was successful without errors.


Viewing all articles
Browse latest Browse all 44

Latest Images

Trending Articles





Latest Images