リビジョン | 112f2316c2b09094f162b73cf28f1cdd4535e73b (tree) |
---|---|
日時 | 2017-06-02 00:17:28 |
作者 | umorigu <umorigu@gmai...> |
コミッター | umorigu |
BugTrack/2422 Counter plugin supports MySQL
@@ -16,7 +16,10 @@ define('PLUGIN_COUNTER_USE_DB', 0); | ||
16 | 16 | define('PLUGIN_COUNTER_DB_CONNECT_STRING', 'sqlite:counter/counter.db'); |
17 | 17 | define('PLUGIN_COUNTER_DB_USERNAME', ''); |
18 | 18 | define('PLUGIN_COUNTER_DB_PASSWORD', ''); |
19 | -define('PLUGIN_COUNTER_DB_OPTIONS', null); | |
19 | +$plugin_counter_db_options = null; | |
20 | +// For MySQL | |
21 | +// $plugin_counter_db_options = array(PDO::MYSQL_ATTR_INIT_COMMAND => | |
22 | +// "SET NAMES utf8mb4 COLLATE utf8mb4_bin"); | |
20 | 23 | |
21 | 24 | define('PLUGIN_COUNTER_DB_TABLE_NAME_PREFIX', ''); |
22 | 25 |
@@ -59,7 +62,7 @@ EOD; | ||
59 | 62 | // Return a summary |
60 | 63 | function plugin_counter_get_count($page) |
61 | 64 | { |
62 | - global $vars; | |
65 | + global $vars, $plugin_counter_db_options; | |
63 | 66 | static $counters = array(); |
64 | 67 | static $default; |
65 | 68 | $page_counter_t = PLUGIN_COUNTER_DB_TABLE_NAME_PREFIX . 'page_counter'; |
@@ -88,7 +91,7 @@ function plugin_counter_get_count($page) | ||
88 | 91 | try { |
89 | 92 | $pdo = new PDO(PLUGIN_COUNTER_DB_CONNECT_STRING, |
90 | 93 | PLUGIN_COUNTER_DB_USERNAME, PLUGIN_COUNTER_DB_PASSWORD, |
91 | - PLUGIN_COUNTER_DB_OPTIONS); | |
94 | + $plugin_counter_db_options); | |
92 | 95 | $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
93 | 96 | $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); |
94 | 97 | $pdo->setAttribute(PDO::ATTR_TIMEOUT, 5); |
@@ -204,15 +207,16 @@ function plugin_counter_get_count($page) | ||
204 | 207 | * php -r "include 'plugin/counter.inc.php'; plugin_counter_tool_setup_table();" |
205 | 208 | */ |
206 | 209 | function plugin_counter_tool_setup_table() { |
210 | + global $plugin_counter_db_options; | |
207 | 211 | $page_counter_t = PLUGIN_COUNTER_DB_TABLE_NAME_PREFIX . 'page_counter'; |
208 | 212 | $pdo = new PDO(PLUGIN_COUNTER_DB_CONNECT_STRING, |
209 | 213 | PLUGIN_COUNTER_DB_USERNAME, PLUGIN_COUNTER_DB_PASSWORD, |
210 | - PLUGIN_COUNTER_DB_OPTIONS); | |
214 | + $plugin_counter_db_options); | |
211 | 215 | $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
212 | 216 | $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); |
213 | 217 | $r = $pdo->exec( |
214 | 218 | "CREATE TABLE $page_counter_t ( |
215 | - page_name VARCHAR(300) PRIMARY KEY, | |
219 | + page_name VARCHAR(190) PRIMARY KEY, | |
216 | 220 | total INTEGER NOT NULL, |
217 | 221 | update_date VARCHAR(20) NOT NULL, |
218 | 222 | today_viewcount INTEGER NOT NULL, |