phpOMS/DataStorage/Database/Connection/SqlServerConnection.php
Dennis Eichhorn 14d4061beb Fixes during secondary app dev
While working on another app some bugs came up that are related to the
way the framework is included and working in combination with the app.
These changes make it more general purpose friendly.
2016-09-07 20:54:28 +02:00

80 lines
2.5 KiB
PHP

<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace phpOMS\DataStorage\Database\Connection;
use phpOMS\DataStorage\Database\DatabaseStatus;
use phpOMS\DataStorage\Database\DatabaseType;
use phpOMS\DataStorage\Database\Query\Grammar\MysqlGrammar;
use phpOMS\DataStorage\Database\Schema\Grammar\MysqlGrammar as MysqlSchemaGrammar;
/**
* Database handler.
*
* Handles the database connection.
* Implementing wrapper functions for multiple databases is planned (far away).
*
* @category Framework
* @package phpOMS\DataStorage\Database
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class SqlServerConnection extends ConnectionAbstract
{
/**
* Object constructor.
*
* Creates the database object and overwrites all default values.
*
* @param string[] $dbdata the basic database information for establishing a connection
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct(array $dbdata)
{
$this->type = DatabaseType::SQLSRV;
$this->grammar = new MysqlGrammar();
$this->schemaGrammar = new MysqlSchemaGrammar();
$this->connect($dbdata);
}
/**
* {@inheritdoc}
*/
public function connect(array $dbdata = null)
{
$this->close();
$this->dbdata = isset($dbdata) ? $dbdata : $this->dbdata;
$this->prefix = $dbdata['prefix'];
try {
$this->con = new \PDO('dblib:host=' . $this->dbdata['host'] . ':' . $this->dbdata['port'] . ';dbname=' . $this->dbdata['database'] . ';charset=utf8', $this->dbdata['login'], $this->dbdata['password']);
$this->con->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
$this->con->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$this->status = DatabaseStatus::OK;
} catch (\PDOException $e) {
$this->status = DatabaseStatus::MISSING_DATABASE;
$this->con = null;
} finally {
$this->dbdata['password'] = '****';
}
}
}