WordPress database error for query INSERT INTO

I am trying to insert data into a custom table. I am using a mysql db with phpmyadmin in my backend. However, I get the following error:

[28-Jun-2018 19:36:05 UTC] WordPress database error for query INSERT INTO `wp_ticker` (`coin_id`, `price`, `volume_24h`, `market_cap`, `percent_change_1h`, `percent_change_24h`, `percent_change_7d`, `created_at`, `updated_at`) VALUES (‘2856’, ‘0.00469682’, ‘1471270’, ‘135309340’, ‘0.56’, ‘-0.45’, ‘-22.2’, ‘2018-06-28 19:36:05’, ‘2018-06-28 19:36:05’) made by do_action_ref_array, WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, Market->updateMarket

The structure of the table looks like the following:

CREATE TABLE {$wpdb->prefix}ticker (
coin_id bigint(20) NOT NULL,
price longtext NOT NULL,
volume_24h bigint(20) NOT NULL,
market_cap bigint(20) NOT NULL,
percent_change_1h DECIMAL(15,8) NOT NULL,
percent_change_24h DECIMAL(15,8) NOT NULL,
percent_change_7d DECIMAL(15,8) NOT NULL,
created_at datetime NULL,
updated_at datetime NULL,
FOREIGN KEY (coin_id) REFERENCES {$wpdb->prefix}coins(id)

I am preparing my data like the following:

$resTicker = array(
‘coin_id’ => intval($coin_id),
‘price’ => $tick->price,
‘volume_24h’ => $tick->volume_24h,
‘market_cap’ => floatval($tick->market_cap),
‘percent_change_1h’ => floatval($tick->percent_change_1h),
‘percent_change_24h’ => floatval($tick->percent_change_24h),
‘percent_change_7d’ => floatval($tick->percent_change_7d),

//check if the above ticker record exists already in the db
$recordTickerExists = $wpdb->get_results(
“SELECT * FROM {$wpdb->prefix}ticker
price = %s
AND coin_id = %s
AND market_cap = %s
floatval($tick->price), $coin_id, floatval($tick->market_cap)

if ( $recordTickerExists == 0 || $recordTickerExists == null ) {
// ticker does not exists else do nothing
try {
$resTicker[‘created_at’] = date(‘Y-m-d H:i:s’);
$resTicker[‘updated_at’] = date(‘Y-m-d H:i:s’);
$wpdb->insert(“{$wpdb->prefix}ticker”, $resTicker);
} catch (Exception $ex) {
// …

Any suggestions what I am doing wrong or see further information on the error?

I appreciate your replies!

Read more here:: WordPress database error for query INSERT INTO

Leave a Reply

Your email address will not be published. Required fields are marked *