1
0
Fork 0
mirror of https://codeberg.org/demostf/api.git synced 2026-06-03 18:04:08 +02:00

upload wip

This commit is contained in:
Robin Appelman 2017-01-31 13:34:54 +01:00
commit fca5d7b0a6
15 changed files with 2146 additions and 164 deletions

View file

@ -1,27 +1,31 @@
<?php namespace Providers;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
use Doctrine\DBAL\Query\QueryBuilder;
use LessQL\Database;
class BaseProvider {
/**
* @var \PDO
* @var Connection
*/
protected $pdo;
protected $connection;
/**
* @var \LessQL\Database
*/
protected $db;
public function __construct(\PDO $pdo) {
$this->pdo = $pdo;
$this->db = new Database($pdo);
public function __construct(Connection $connection) {
$this->connection = $connection;
$this->db = new Database($connection->getWrappedConnection());
$this->dbConfig();
}
private function dbConfig() {
$driver = $this->pdo->getAttribute(\PDO::ATTR_DRIVER_NAME);
if ($driver === 'mysql') {
$platform = $this->connection->getDatabasePlatform();
if ($platform instanceof MySqlPlatform) {
$this->db->setIdentifierDelimiter("`");
} else {
$this->db->setIdentifierDelimiter('"');
@ -44,16 +48,23 @@ class BaseProvider {
protected function query($sql, array $params = []) {
$delimiter = $this->db->getIdentifierDelimiter();
$driver = $this->pdo->getAttribute(\PDO::ATTR_DRIVER_NAME);
$platform = $this->connection->getDatabasePlatform();
$sql = str_replace('`', $delimiter, $sql);
if ($driver === 'pgsql') {
if ($platform instanceof PostgreSqlPlatform) {
$sql = str_replace('FROM_UNIXTIME(', 'to_timestamp(', $sql);
}
$query = $this->pdo->prepare($sql, $params);
$query = $this->connection->prepare($sql);
$query->execute($params);
return $query;
}
/**
* @return QueryBuilder
*/
protected function getQueryBuilder() {
return new QueryBuilder($this->connection);
}
}