From 603406bf4d25b3870dafa7296931f750fb9d4811 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 6 Jun 2016 18:31:13 +0200 Subject: PhpStorm stuff --- inc/database.inc.php | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) (limited to 'inc/database.inc.php') diff --git a/inc/database.inc.php b/inc/database.inc.php index c3901453..ee45f6c0 100644 --- a/inc/database.inc.php +++ b/inc/database.inc.php @@ -13,36 +13,26 @@ class Database */ private static $dbh = false; private static $statements = array(); - - /** - * Get database schema version - used for checking for updates - * @return int Version of db schema - */ - public static function getExpectedSchemaVersion() - { - return 12; - } - - public static function needSchemaUpdate() - { - return Property::getCurrentSchemaVersion() < self::getExpectedSchemaVersion(); - } /** * Connect to the DB if not already connected. */ - private static function init() + public static function init($returnSuccess = false) { if (self::$dbh !== false) - return; + return true; try { - if (CONFIG_SQL_FORCE_UTF8) + if (CONFIG_SQL_FORCE_UTF8) { self::$dbh = new PDO(CONFIG_SQL_DSN, CONFIG_SQL_USER, CONFIG_SQL_PASS, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")); - else + } else { self::$dbh = new PDO(CONFIG_SQL_DSN, CONFIG_SQL_USER, CONFIG_SQL_PASS); + } } catch (PDOException $e) { + if ($returnSuccess) + return false; Util::traceError('Connecting to the local database failed: ' . $e->getMessage()); } + return true; } /** @@ -62,7 +52,7 @@ class Database /** * Execute the given query and return the number of rows affected. * Mostly useful for UPDATEs or INSERTs - * + * * @param string $query Query to run * @param array $args Arguments to query * @param boolean $ignoreError Ignore query errors and just return false @@ -78,7 +68,7 @@ class Database /** * Get id (promary key) of last row inserted. - * + * * @return int the id */ public static function lastInsertId() @@ -91,6 +81,7 @@ class Database * Note that this will re-use PDOStatements, so if you run the same * query again with different params, do not rely on the first PDOStatement * still being valid. If you need to do something fancy, use Database::prepare + * * @return \PDOStatement The query result object */ public static function simpleQuery($query, $args = array(), $ignoreError = false) @@ -109,9 +100,9 @@ class Database } return self::$statements[$query]; } catch (Exception $e) { - if ($ignoreError) - return false; - Util::traceError("Database Error: \n" . $e->getMessage()); + if ($ignoreError) + return false; + Util::traceError("Database Error: \n" . $e->getMessage()); } return false; } -- cgit v1.2.3-55-g7522