X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=inc%2Fpoche%2FDatabase.class.php;h=210ebb74cc279b0f55d61cced87dd46108f36206;hb=refs%2Ftags%2F1.9beta2;hp=2c80b64b5dff24687777be87754134057be01091;hpb=887b015def3098f1e898e7bf3338fa2d093b6d95;p=github%2Fwallabag%2Fwallabag.git diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index 2c80b64b..210ebb74 100755 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -23,12 +23,23 @@ class Database { { switch (STORAGE) { case 'sqlite': + // Check if /db is writeable + if ( !is_writable(STORAGE_SQLITE) || !is_writable(dirname(STORAGE_SQLITE))) { + die('An error occured: "db" directory must be writeable for your web server user!'); + } $db_path = 'sqlite:' . STORAGE_SQLITE; $this->handle = new PDO($db_path); break; case 'mysql': - $db_path = 'mysql:host=' . STORAGE_SERVER . ';dbname=' . STORAGE_DB; - $this->handle = new PDO($db_path, STORAGE_USER, STORAGE_PASSWORD); + if (MYSQL_USE_UTF8MB4) { + $db_path = 'mysql:host=' . STORAGE_SERVER . ';dbname=' . STORAGE_DB . ';charset=utf8mb4'; + $this->handle = new PDO($db_path, STORAGE_USER, STORAGE_PASSWORD, array( + PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4', + )); + } else { + $db_path = 'mysql:host=' . STORAGE_SERVER . ';dbname=' . STORAGE_DB; + $this->handle = new PDO($db_path, STORAGE_USER, STORAGE_PASSWORD); + } break; case 'postgres': $db_path = 'pgsql:host=' . STORAGE_SERVER . ';dbname=' . STORAGE_DB; @@ -113,10 +124,10 @@ class Database { $query = $this->executeQuery($sql, array()); } - public function install($login, $password) + public function install($login, $password, $email = '') { $sql = 'INSERT INTO users ( username, password, name, email) VALUES (?, ?, ?, ?)'; - $params = array($login, $password, $login, ' '); + $params = array($login, $password, $login, $email); $query = $this->executeQuery($sql, $params); $sequence = ''; @@ -287,7 +298,7 @@ class Database { $sql_limit = "LIMIT ".$limit." OFFSET 0"; } - $sql = "SELECT * FROM entries WHERE (content = '' OR content IS NULL) AND title LIKE 'Untitled - Import%' AND user_id=? ORDER BY id " . $sql_limit; + $sql = "SELECT * FROM entries WHERE (content = '' OR content IS NULL) AND title LIKE '%Import%' AND user_id=? ORDER BY id " . $sql_limit; $query = $this->executeQuery($sql, array($user_id)); $entries = $query->fetchAll(); @@ -296,7 +307,7 @@ class Database { public function retrieveUnfetchedEntriesCount($user_id) { - $sql = "SELECT count(*) FROM entries WHERE (content = '' OR content IS NULL) AND title LIKE 'Untitled - Import%' AND user_id=?"; + $sql = "SELECT count(*) FROM entries WHERE (content = '' OR content IS NULL) AND title LIKE '%Import%' AND user_id=?"; $query = $this->executeQuery($sql, array($user_id)); list($count) = $query->fetch(); @@ -400,6 +411,14 @@ class Database { return $count; } + public function getRandomId($row, $user_id) { + $sql = "SELECT id FROM entries WHERE user_id=? LIMIT 1 OFFSET ? "; + $params = array($user_id, $row); + $query = $this->executeQuery($sql, $params); + + return $query->fetchAll(); + } + public function updateContent($id, $content, $user_id) {