Created
March 3, 2016 07:52
-
-
Save suneo3476/010f06b752d6ca0234ff to your computer and use it in GitHub Desktop.
mysql-cli上の実行結果がPHPDatabaseObjectライブラリで再現されないバグ。DATETIME
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getTrendRanking.phpの実行結果画面 | |
====================== | |
array(0) { (←MorphemeMapper.php中のdebugDumpParams()による出力、mysql-cliと同じ結果が入るはずなのに空) | |
} | |
SQL: [377] | |
select morpheme_ID, surface_form, count(surface_form) as score | |
from morpheme,atc_table | |
where morpheme.article_ID = atc_table.article_ID | |
and pos = '名詞' | |
and tokenize_index < 10 | |
and morpheme.article_ID in | |
(select article_ID from atc_table | |
where created_at between cast(':start' as date) and cast(':end' as date) ) | |
group by surface_form | |
order by score desc limit 50; | |
Params: 2 | |
Key: Name: [6] :start | |
paramno=-1 | |
name=[6] ":start" | |
is_param=1 | |
param_type=2 | |
Key: Name: [4] :end | |
paramno=-1 | |
name=[4] ":end" | |
is_param=1 | |
param_type=2 | |
[] (←getTrendRanking.phpのレスポンス) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
ini_set( 'display_errors', 1 ); | |
require_once 'DataModel.php'; | |
require_once 'DataMapper.php'; | |
require_once 'Morpheme.php'; | |
require_once 'MorphemeMapper.php'; | |
require_once 'bootstrap.php'; | |
require_once 'functions.php'; | |
require_once 'db.conf.php'; | |
if(!isset($_GET['centerdate'])||$_GET['centerdate']==='' | |
||!isset($_GET['termsize'])||$_GET['termsize']===''){ | |
$errors[] = 'centerdate & termsize are nothing!'; | |
}else{ | |
header('Content-Type: application/json'); | |
$format = 'Y-m-d H:i:s'; | |
$centerdate = new DateTime($_GET['centerdate']); | |
$termsize = $_GET['termsize']; | |
switch($termsize){ | |
case '年': | |
$start = $centerdate->modify('+6 months')->format($format); | |
$end = $centerdate->modify('-12 months')->format($format); | |
break; | |
case '月': | |
$start = $centerdate->modify('+15 days')->format($format); | |
$end = $centerdate->modify('-30 days')->format($format); | |
break; | |
case '週': | |
$start = $centerdate->modify('+3 days')->format($format); | |
$end = $centerdate->modify('-6 days')->format($format); | |
break; | |
default: | |
break; | |
} | |
// echo json_encode($start.':'.$end.'<br>' ,JSON_UNESCAPED_UNICODE); | |
$mmapper = new MorphemeMapper(getPDO('hamazo')); | |
$data = $mmapper->findTrend($start,$end);//結果が空… | |
echo json_encode($data,JSON_UNESCAPED_UNICODE); | |
exit; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ... */ | |
function findTrend($start,$end){//期間の開始と終了を渡すと単語ランキングを返す | |
$stmt = $this->_pdo->prepare(" | |
select morpheme_ID, surface_form, count(surface_form) as score | |
from morpheme,atc_table | |
where morpheme.article_ID = atc_table.article_ID | |
and pos = '名詞' | |
and tokenize_index < 10 | |
and morpheme.article_ID in | |
(select article_ID from atc_table | |
where created_at between cast(':start' as date) and cast(':end' as date) ) | |
group by surface_form | |
order by score desc limit 50;"); | |
$stmt->bindParam(':start', $start, PDO::PARAM_STR,19); | |
$stmt->bindParam(':end', $end, PDO::PARAM_STR,19); | |
$stmt->execute(); | |
$this->_decorate($stmt); // <- pdo core lib from https://github.com/hirak/pdo-datamapper-example/tree/master/lib | |
$stmt->debugDumpParams(); | |
return $stmt->fetchAll(PDO::FETCH_ASSOC); | |
} | |
/* ... */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
↓getTrendRanking.phpの実行結果で返ってきて欲しいデータ | |
====================== | |
+-------------+--------------+-------+ | |
| morpheme_ID | surface_form | score | | |
+-------------+--------------+-------+ | |
| 109017774 | 、 | 489 | | |
| 51487483 | 今日 | 202 | | |
| 53311952 | 日 | 149 | | |
| 80222054 | ・ | 106 | | |
| 100198840 | 昨日 | 102 | | |
| 13549564 | 本日 | 97 | | |
| 26461258 | 2 | 86 | | |
| 38641254 | 1 | 83 | | |
| 14234230 | さん | 71 | | |
| 76221010 | 浜松 | 65 | | |
(以下略) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment