summaryrefslogtreecommitdiffstats
path: root/inc/database.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2016-06-06 18:31:13 +0200
committerSimon Rettberg2016-06-06 18:31:13 +0200
commit603406bf4d25b3870dafa7296931f750fb9d4811 (patch)
treec6dbd0366c150bbab1564961d2bfd4e41f274b19 /inc/database.inc.php
parent[install] Work on install mechanism so modules can independently install/upda... (diff)
downloadslx-admin-603406bf4d25b3870dafa7296931f750fb9d4811.tar.gz
slx-admin-603406bf4d25b3870dafa7296931f750fb9d4811.tar.xz
slx-admin-603406bf4d25b3870dafa7296931f750fb9d4811.zip
PhpStorm stuff
Diffstat (limited to 'inc/database.inc.php')
-rw-r--r--inc/database.inc.php37
1 files changed, 14 insertions, 23 deletions
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;
}