我正在尝试将数据插入到自定义表中。我在后端使用带有phpmyadmin的mysql数据库。但是,我得到以下错误:
[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
表的结构如下所示:
CREATE TABLE {$wpdb->prefix}ticker (
id bigint(20) NOT NULL AUTO_INCREMENT,
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,
PRIMARY KEY (id),
FOREIGN KEY (coin_id) REFERENCES {$wpdb->prefix}coins(id)
);
我正在准备以下数据:
$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(
$wpdb->prepare(
"SELECT * FROM {$wpdb->prefix}ticker
WHERE
price = %s
AND coin_id = %s
AND market_cap = %s
LIMIT 1",
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) {
// ...
}
}
有什么建议我做错了什么,或者看到关于错误的更多信息吗?
感谢您的回复!