diff --git a/src/Ease/SQL/Engine.php b/src/Ease/SQL/Engine.php index adce862..eca57c9 100644 --- a/src/Ease/SQL/Engine.php +++ b/src/Ease/SQL/Engine.php @@ -42,24 +42,6 @@ public function __construct($identifier = null, $options = []) } } - /** - * SetUp Object to be ready for connect - * - * @param array $options Object Options (company,url,user,password,evidence, - * prefix,defaultUrlParams,debug) - */ - public function setUp($options = []) - { - $this->setupProperty($options, 'dbType', 'DB_TYPE'); - $this->setupProperty($options, 'server', 'DB_HOST'); - $this->setupProperty($options, 'username', 'DB_USERNAME'); - $this->setupProperty($options, 'password', 'DB_PASSWORD'); - $this->setupProperty($options, 'database', 'DB_DATABASE'); - $this->setupProperty($options, 'port', 'DB_PORT'); - $this->setupProperty($options, 'connectionSettings', 'DB_SETUP'); - $this->setupProperty($options, 'myTable'); - } - /** * * @return \Envms\FluentPDO diff --git a/src/Ease/SQL/Orm.php b/src/Ease/SQL/Orm.php index 57208e7..68749e1 100644 --- a/src/Ease/SQL/Orm.php +++ b/src/Ease/SQL/Orm.php @@ -1,4 +1,5 @@ */ -trait Orm -{ +trait Orm { + /** * IP serveru. * @@ -90,48 +91,64 @@ trait Orm */ public $errorNumber = null; + /** + * SetUp Object to be ready for connect + * + * @param array $options Object Options (company,url,user,password,evidence, + * prefix,defaultUrlParams,debug) + */ + public function setUp($options = []) { + $this->setupProperty($options, 'dbType', 'DB_TYPE'); + $this->setupProperty($options, 'server', 'DB_HOST'); + $this->setupProperty($options, 'username', 'DB_USERNAME'); + $this->setupProperty($options, 'password', 'DB_PASSWORD'); + $this->setupProperty($options, 'database', 'DB_DATABASE'); + $this->setupProperty($options, 'port', 'DB_PORT'); + $this->setupProperty($options, 'connectionSettings', 'DB_SETUP'); + $this->setupProperty($options, 'myTable'); + } + /** * Perform connect to database. * * @return \PDO SQL connector */ - public function pdoConnect() - { + public function pdoConnect() { $result = false; if (is_null($this->dbType)) { $result = null; } else { switch ($this->dbType) { case 'mysql': - $result = new \PDO($this->dbType.':dbname='.$this->database.';host='.$this->server.';port='.$this->port.';charset=utf8', - $this->username, $this->password, - [\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'utf8\'']); + $result = new \PDO($this->dbType . ':dbname=' . $this->database . ';host=' . $this->server . ';port=' . $this->port . ';charset=utf8', + $this->username, $this->password, + [\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'utf8\'']); break; case 'pgsql': - $result = new \PDO($this->dbType.':dbname='.$this->database.';host='.$this->server.';port='.$this->port, - $this->username, $this->password); + $result = new \PDO($this->dbType . ':dbname=' . $this->database . ';host=' . $this->server . ';port=' . $this->port, + $this->username, $this->password); if (is_object($result)) { $result->exec("SET NAMES 'UTF-8'"); } break; default: - throw new \Ease\Exception(_('Unimplemented Database type').': '.$this->dbType); + throw new \Ease\Exception(_('Unimplemented Database type') . ': ' . $this->dbType); break; } if ($result instanceof \PDO) { $this->errorNumber = $result->errorCode(); - $this->errorText = $result->errorInfo(); + $this->errorText = $result->errorInfo(); if ($this->errorNumber != '00000') { - $this->addStatusMessage('Connect: error #'.$this->errorNumer.' '.$this->errorText, - 'error'); + $this->addStatusMessage('Connect: error #' . $this->errorNumer . ' ' . $this->errorText, + 'error'); $result = false; } else { if (!empty($this->connectionSettings)) - foreach ($this->connectionSettings as $setName => $SetValue) { + foreach ($this->connectionSettings as $setName => $SetValue) { if (strlen($setName)) { $this->getPdo->exec("SET $setName $SetValue"); } @@ -148,8 +165,7 @@ public function pdoConnect() * * @return \PDO */ - public function getPdo() - { + public function getPdo() { if (!$this->pdo instanceof \PDO) { $this->pdo = $this->pdoConnect(); } @@ -161,11 +177,27 @@ public function getPdo() * * @return \Envms\FluentPDO */ - public function getFluentPDO() - { + public function getFluentPDO() { if (!$this->fluent instanceof \Envms\FluentPDO) { $this->fluent = new \Envms\FluentPDO\Query($this->getPdo()); } return $this->fluent; } + + /** + * + * @return string + */ + public function getMyTable() { + return $this->myTable; + } + + /** + * + * @param string $tablename + */ + public function setMyTable($tablename) { + $this->myTable = $tablename; + } + }