diff options
Diffstat (limited to 'inc/poche/Database.class.php')
-rwxr-xr-x | inc/poche/Database.class.php | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index f6ba4708..65675afe 100755 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php | |||
@@ -31,10 +31,15 @@ class Database { | |||
31 | $this->handle = new PDO($db_path); | 31 | $this->handle = new PDO($db_path); |
32 | break; | 32 | break; |
33 | case 'mysql': | 33 | case 'mysql': |
34 | $db_path = 'mysql:host=' . STORAGE_SERVER . ';dbname=' . STORAGE_DB . ';charset=utf8mb4'; | 34 | if (MYSQL_USE_UTF8MB4) { |
35 | $this->handle = new PDO($db_path, STORAGE_USER, STORAGE_PASSWORD, array( | 35 | $db_path = 'mysql:host=' . STORAGE_SERVER . ';dbname=' . STORAGE_DB . ';charset=utf8mb4'; |
36 | PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4', | 36 | $this->handle = new PDO($db_path, STORAGE_USER, STORAGE_PASSWORD, array( |
37 | )); | 37 | PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4', |
38 | )); | ||
39 | } else { | ||
40 | $db_path = 'mysql:host=' . STORAGE_SERVER . ';dbname=' . STORAGE_DB; | ||
41 | $this->handle = new PDO($db_path, STORAGE_USER, STORAGE_PASSWORD); | ||
42 | } | ||
38 | break; | 43 | break; |
39 | case 'postgres': | 44 | case 'postgres': |
40 | $db_path = 'pgsql:host=' . STORAGE_SERVER . ';dbname=' . STORAGE_DB; | 45 | $db_path = 'pgsql:host=' . STORAGE_SERVER . ';dbname=' . STORAGE_DB; |
@@ -293,7 +298,7 @@ class Database { | |||
293 | $sql_limit = "LIMIT ".$limit." OFFSET 0"; | 298 | $sql_limit = "LIMIT ".$limit." OFFSET 0"; |
294 | } | 299 | } |
295 | 300 | ||
296 | $sql = "SELECT * FROM entries WHERE (content = '' OR content IS NULL) AND title LIKE 'Untitled - Import%' AND user_id=? ORDER BY id " . $sql_limit; | 301 | $sql = "SELECT * FROM entries WHERE (content = '' OR content IS NULL) AND title LIKE '%Import%' AND user_id=? ORDER BY id " . $sql_limit; |
297 | $query = $this->executeQuery($sql, array($user_id)); | 302 | $query = $this->executeQuery($sql, array($user_id)); |
298 | $entries = $query->fetchAll(); | 303 | $entries = $query->fetchAll(); |
299 | 304 | ||
@@ -302,7 +307,7 @@ class Database { | |||
302 | 307 | ||
303 | public function retrieveUnfetchedEntriesCount($user_id) | 308 | public function retrieveUnfetchedEntriesCount($user_id) |
304 | { | 309 | { |
305 | $sql = "SELECT count(*) FROM entries WHERE (content = '' OR content IS NULL) AND title LIKE 'Untitled - Import%' AND user_id=?"; | 310 | $sql = "SELECT count(*) FROM entries WHERE (content = '' OR content IS NULL) AND title LIKE '%Import%' AND user_id=?"; |
306 | $query = $this->executeQuery($sql, array($user_id)); | 311 | $query = $this->executeQuery($sql, array($user_id)); |
307 | list($count) = $query->fetch(); | 312 | list($count) = $query->fetch(); |
308 | 313 | ||
@@ -406,6 +411,16 @@ class Database { | |||
406 | 411 | ||
407 | return $count; | 412 | return $count; |
408 | } | 413 | } |
414 | public function getRandomId($user_id) { | ||
415 | $random = (STORAGE == 'mysql') ? 'RAND()' : 'RANDOM()'; | ||
416 | $sql = "SELECT id FROM entries WHERE user_id=? ORDER BY ". $random . " LIMIT 1"; | ||
417 | $params = array($user_id); | ||
418 | $query = $this->executeQuery($sql, $params); | ||
419 | $id = $query->fetchAll(); | ||
420 | |||
421 | return $id; | ||
422 | } | ||
423 | |||
409 | 424 | ||
410 | public function updateContent($id, $content, $user_id) | 425 | public function updateContent($id, $content, $user_id) |
411 | { | 426 | { |