You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
2.4 KiB
PHTML

<?php
namespace Engelsystem\Database;
use Illuminate\Database\Capsule\Manager as CapsuleManager;
use Illuminate\Database\Connection as DatabaseConnection;
use PDO;
class Db
{
/** @var CapsuleManager */
protected static $dbManager;
/**
* Set the database connection manager
*
* @param CapsuleManager $dbManager
*/
public static function setDbManager($dbManager)
{
self::$dbManager = $dbManager;
}
/**
* Run a select query
*
* @param string $query
* @param array $bindings
* @return array[]
*/
public static function select($query, array $bindings = [])
{
$return = self::connection()->select($query, $bindings);
// @TODO: Remove type casting
foreach ($return as $key => $value) {
$return[$key] = (array)$value;
}
return $return;
}
7 years ago
/**
* Run a select query and return only the first result or null if no result is found.
7 years ago
*
* @param string $query
* @param array $bindings
* @return array
*/
public static function selectOne($query, array $bindings = [])
{
$result = self::connection()->selectOne($query, $bindings);
7 years ago
// @TODO: remove typecast
return (array)$result;
}
/**
* Run an insert query
*
* @param string $query
* @param array $bindings
* @return bool
*/
public static function insert($query, array $bindings = [])
{
return self::connection()->insert($query, $bindings);
}
/**
* Run an update query
*
* @param string $query
* @param array $bindings
* @return int
*/
public static function update($query, array $bindings = [])
{
return self::connection()->update($query, $bindings);
}
/**
* Run a delete query
*
* @param string $query
* @param array $bindings
* @return int
*/
public static function delete($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();
}
}