· 8 years ago · Jun 28, 2018, 07:52 PM
1[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
2
3CREATE TABLE {$wpdb->prefix}ticker (
4 id bigint(20) NOT NULL AUTO_INCREMENT,
5 coin_id bigint(20) NOT NULL,
6 price longtext NOT NULL,
7 volume_24h bigint(20) NOT NULL,
8 market_cap bigint(20) NOT NULL,
9 percent_change_1h DECIMAL(15,8) NOT NULL,
10 percent_change_24h DECIMAL(15,8) NOT NULL,
11 percent_change_7d DECIMAL(15,8) NOT NULL,
12 created_at datetime NULL,
13 updated_at datetime NULL,
14 PRIMARY KEY (id),
15 FOREIGN KEY (coin_id) REFERENCES {$wpdb->prefix}coins(id)
16);
17
18$resTicker = array(
19 'coin_id' => intval($coin_id),
20 'price' => $tick->price,
21 'volume_24h' => $tick->volume_24h,
22 'market_cap' => floatval($tick->market_cap),
23 'percent_change_1h' => floatval($tick->percent_change_1h),
24 'percent_change_24h' => floatval($tick->percent_change_24h),
25 'percent_change_7d' => floatval($tick->percent_change_7d),
26 );
27
28 //check if the above ticker record exists already in the db
29 $recordTickerExists = $wpdb->get_results(
30 $wpdb->prepare(
31 "SELECT * FROM {$wpdb->prefix}ticker
32 WHERE
33 price = %s
34 AND coin_id = %s
35 AND market_cap = %s
36 LIMIT 1",
37 floatval($tick->price), $coin_id, floatval($tick->market_cap)
38 )
39 );
40
41 if ( $recordTickerExists == 0 || $recordTickerExists == null ) {
42 // ticker does not exists else do nothing
43 try {
44 $resTicker['created_at'] = date('Y-m-d H:i:s');
45 $resTicker['updated_at'] = date('Y-m-d H:i:s');
46 $wpdb->insert("{$wpdb->prefix}ticker", $resTicker);
47 } catch (Exception $ex) {
48 // ...
49 }
50 }