別ファイルから下記のメソッド(insertmarket)を呼び出そうとしているのですが、うまくいきません。
・データベース接続は正常に動作
・エラーは表示されない
おそらく下記のコードに問題があると推測しているのですが、問題点が分かりそうな方がいましたら、ご教示いただけると幸いです。
MarketSummariesDao.class.php
PHP
1 /** 2 * 3 * @return multitype:string 4 */ 5private function _getFields() { 6 7 $fields = array(); 8 9 $fields[] = 'board_history_id'; 10 $fields[] = 'symbole'; 11 $fields[] = 'pair'; 12 $fields[] = 'last_price'; 13 $fields[] = 'change_rate'; 14 $fields[] = 'high_price'; 15 $fields[] = 'low_price'; 16 $fields[] = 'bid_price'; 17 $fields[] = 'ask_price'; 18 $fields[] = 'volume'; 19 $fields[] = 'btc_volume'; 20 $fields[] = 'trade_count'; 21 $fields[] = 'buy_order_count'; 22 $fields[] = 'sell_order_count'; 23 $fields[] = 'insert_date'; 24 $fields[] = 'insert_datetime'; 25 26 return $fields; 27 } 28 29 /** 30 * データ挿入 31 * @param unknown $pdo 32 * @param unknown $data 33 * @param unknown $date 34 */ 35public function insertMarket($pdo, $data, $date) { 36 37 //読み込まれているか確認 → 動作する 38 file_put_contents(dirname(__FILE__).'/../../log/error.txt', "テスト1", FILE_APPEND ); 39 40 $fields = $this->_getFields(); 41 42 try { 43 44 $sql = ''; 45 $sql .= 'INSERT INTO '; 46 $sql .= 'markets '; 47 $sql .= '('; 48 $sql .= implode(', ', $fields); 49 $sql .= ') VALUES ('; 50 $sql .= 'NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?'; 51 $sql .= ') '; 52 53 $stmt = $pdo->prepare($sql); 54 55 foreach ( $data as $key => $value ) { 56 $stmt->bindValue($key+1, $value, PDO::PARAM_STR); 57 } 58 59 //INSERTの内容を確認する → 動作する 60 file_put_contents(dirname(__FILE__).'/../../log/error.txt', print_r($stmt,TRUE), FILE_APPEND ); 61 62 $stmt->execute(); 63 64 } catch (Exception $e) { 65 echo $e->getMessage(); // 詳細なエラーを表示する 66 exit; 67 } 68 69 //読み込まれているか確認 → 動作しない 70file_put_contents(dirname(__FILE__).'/../../log/error.txt', "テスト2", FILE_APPEND ); 71 }
error.txt
PHP
1テスト1 2PDOStatement Object 3( 4 [queryString] => INSERT INTO markets (board_history_id, symbole, pair, last_price, change_rate, high_price, low_price, bid_price, ask_price, volume, btc_volume, trade_count, buy_order_count, sell_order_count, insert_date, insert_datetime) VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) 5)
回答2件
あなたの回答
tips
プレビュー