summaryrefslogtreecommitdiff
path: root/src/Database
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2018-01-14 13:32:57 +0100
committerIgor Scheller <igor.scheller@igorshp.de>2018-01-14 13:32:57 +0100
commit0e8cc2f0a73085170df45c6a40e8f3df06a6af51 (patch)
treea38b1c1d7da28f4c95b201ab32d370916e749832 /src/Database
parentd4b36e9bad4c9d64447f053ec19a9f600888b2fe (diff)
database: integrated illuminate/database do Db class, removed unused methods
Diffstat (limited to 'src/Database')
-rw-r--r--src/Database/Db.php99
1 files changed, 17 insertions, 82 deletions
diff --git a/src/Database/Db.php b/src/Database/Db.php
index aa9b1a27..426dd526 100644
--- a/src/Database/Db.php
+++ b/src/Database/Db.php
@@ -3,20 +3,14 @@
namespace Engelsystem\Database;
use Illuminate\Database\Capsule\Manager as CapsuleManager;
+use Illuminate\Database\Connection as DatabaseConnection;
use PDO;
-use PDOStatement;
class Db
{
/** @var CapsuleManager */
protected static $dbManager;
- /** @var PDOStatement */
- protected static $stm = null;
-
- /** @var bool */
- protected static $lastStatus = true;
-
/**
* Set the database connection manager
*
@@ -28,35 +22,6 @@ class Db
}
/**
- * Run a prepared query
- *
- * @param string $query
- * @param array $bindings
- * @return PDOStatement
- */
- public static function query($query, array $bindings = [])
- {
- self::$stm = self::getPdo()->prepare($query);
- self::$lastStatus = self::$stm->execute($bindings);
-
- return self::$stm;
- }
-
- /**
- * Run a sql query
- *
- * @param string $query
- * @return bool
- */
- public static function unprepared($query)
- {
- self::$stm = self::getPdo()->query($query);
- self::$lastStatus = (self::$stm instanceof PDOStatement);
-
- return self::$lastStatus;
- }
-
- /**
* Run a select query
*
* @param string $query
@@ -65,9 +30,13 @@ class Db
*/
public static function select($query, array $bindings = [])
{
- self::query($query, $bindings);
+ $return = self::connection()->select($query, $bindings);
+
+ foreach ($return as $key => $value) {
+ $return[$key] = (array)$value;
+ }
- return self::$stm->fetchAll(PDO::FETCH_ASSOC);
+ return $return;
}
/**
@@ -79,13 +48,13 @@ class Db
*/
public static function selectOne($query, array $bindings = [])
{
- $result = self::select($query, $bindings);
+ $result = self::connection()->selectOne($query, $bindings);
if (empty($result)) {
return null;
}
- return array_shift($result);
+ return (array)$result;
}
/**
@@ -93,13 +62,11 @@ class Db
*
* @param string $query
* @param array $bindings
- * @return int Row count
+ * @return bool
*/
public static function insert($query, array $bindings = [])
{
- self::query($query, $bindings);
-
- return self::$stm->rowCount();
+ return self::connection()->insert($query, $bindings);
}
/**
@@ -111,9 +78,7 @@ class Db
*/
public static function update($query, array $bindings = [])
{
- self::query($query, $bindings);
-
- return self::$stm->rowCount();
+ return self::connection()->update($query, $bindings);
}
/**
@@ -125,37 +90,15 @@ class Db
*/
public static function delete($query, array $bindings = [])
{
- self::query($query, $bindings);
-
- return self::$stm->rowCount();
- }
-
- /**
- * Run a single statement
- *
- * @param string $query
- * @param array $bindings
- * @return bool
- */
- public static function statement($query, array $bindings = [])
- {
- self::query($query, $bindings);
-
- return self::$lastStatus;
+ return self::connection()->delete($query, $bindings);
}
/**
- * Returns the last error
- *
- * @return array
+ * @return DatabaseConnection
*/
- public static function getError()
+ public static function connection()
{
- if (!self::$stm instanceof PDOStatement) {
- return [-1, null, null];
- }
-
- return self::$stm->errorInfo();
+ return self::$dbManager->getConnection();
}
/**
@@ -165,14 +108,6 @@ class Db
*/
public static function getPdo()
{
- return self::$dbManager->getConnection()->getPdo();
- }
-
- /**
- * @return PDOStatement|false|null
- */
- public static function getStm()
- {
- return self::$stm;
+ return self::connection()->getPdo();
}
}