engelsystem/src/Database/Db.php

112 lines
2.3 KiB
PHP
Raw Normal View History

<?php
namespace Engelsystem\Database;
2018-01-14 01:48:50 +01:00
use Illuminate\Database\Capsule\Manager as CapsuleManager;
use Illuminate\Database\Connection as DatabaseConnection;
use PDO;
/** @deprecated */
class Db
{
2018-01-14 01:48:50 +01:00
/** @var CapsuleManager */
protected static $dbManager;
/**
2018-01-14 01:48:50 +01:00
* Set the database connection manager
*
*/
public static function setDbManager(CapsuleManager $dbManager)
{
2018-01-14 01:48:50 +01:00
self::$dbManager = $dbManager;
}
/**
* Run a select query
*
* @param array $bindings
2017-12-25 23:12:52 +01:00
* @return array[]
*/
public static function select(string $query, array $bindings = [])
{
$return = self::connection()->select($query, $bindings);
2018-01-14 17:47:26 +01:00
// @TODO: Remove type casting
foreach ($return as $key => $value) {
$return[$key] = (array)$value;
}
return $return;
}
2017-08-30 00:07:01 +02:00
/**
* Run a select query and return only the first result or null if no result is found.
2017-08-30 00:07:01 +02:00
*
* @param array $bindings
* @return array|null
*/
public static function selectOne(string $query, array $bindings = [])
{
$result = self::connection()->selectOne($query, $bindings);
2017-08-30 00:07:01 +02:00
2018-01-14 17:47:26 +01:00
// @TODO: remove typecast
$result = (array)$result;
if (empty($result)) {
return null;
}
return $result;
}
/**
* Run an insert query
*
* @param array $bindings
* @return bool
*/
public static function insert(string $query, array $bindings = [])
{
return self::connection()->insert($query, $bindings);
}
/**
* Run an update query
*
* @param array $bindings
2017-07-23 11:46:54 +02:00
* @return int
*/
public static function update(string $query, array $bindings = [])
{
return self::connection()->update($query, $bindings);
}
/**
* Run a delete query
*
* @param array $bindings
2017-07-28 18:50:00 +02:00
* @return int
*/
public static function delete(string $query, array $bindings = [])
{
return self::connection()->delete($query, $bindings);
}
/**
* @return DatabaseConnection
*/
public static function connection()
{
return self::$dbManager->getConnection();
}
/**
* Get the PDO instance
*
* @return PDO
*/
public static function getPdo()
{
return self::connection()->getPdo();
}
}