new QI object for sql installations, some tests with it + adjustments towards it
This commit is contained in:
parent
924162dc5f
commit
813ecf397f
@ -1,16 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace SYSTEM\DB;
|
namespace SYSTEM\DB;
|
||||||
|
|
||||||
class Connection extends ConnectionAbstr{
|
class Connection extends ConnectionAbstr{
|
||||||
|
//The open Connection
|
||||||
//The open Connection, either ConnectionPG or ConnectionMYS
|
|
||||||
private $connection = NULL;
|
private $connection = NULL;
|
||||||
//private $dbinfo = NULL;
|
|
||||||
|
|
||||||
//Connects to DB, dependent on DBInfo a connection to a PG or MYS will be established
|
//Connects to DB, dependent on DBInfo a connection will be established
|
||||||
public function __construct(DBInfo $dbinfo = null){
|
public function __construct(DBInfo $dbinfo = null){
|
||||||
//$this->dbinfo = $dbinfo;
|
|
||||||
if(!$dbinfo){
|
if(!$dbinfo){
|
||||||
$dbinfo = \SYSTEM\system::getSystemDBInfo();}
|
$dbinfo = \SYSTEM\system::getSystemDBInfo();}
|
||||||
|
|
||||||
@ -44,4 +39,10 @@ class Connection extends ConnectionAbstr{
|
|||||||
|
|
||||||
public function exec($query){
|
public function exec($query){
|
||||||
return $this->connection->exec($query);}
|
return $this->connection->exec($query);}
|
||||||
|
|
||||||
|
public function trans(){
|
||||||
|
return $this->connection->trans();}
|
||||||
|
|
||||||
|
public function commit(){
|
||||||
|
return $this->connection->commit();}
|
||||||
}
|
}
|
||||||
@ -13,7 +13,8 @@ abstract class ConnectionAbstr {
|
|||||||
abstract public function prepare($stmtName, $stmt, $values);
|
abstract public function prepare($stmtName, $stmt, $values);
|
||||||
//Query Database with normal Statement with $query = SQLString
|
//Query Database with normal Statement with $query = SQLString
|
||||||
abstract public function query($query);
|
abstract public function query($query);
|
||||||
|
abstract public function commit();
|
||||||
|
abstract public function trans();
|
||||||
//Convert Prepared Values to SQL Type identifiers
|
//Convert Prepared Values to SQL Type identifiers
|
||||||
protected static function getPrepareValueType($value){
|
protected static function getPrepareValueType($value){
|
||||||
if(is_double($value)){
|
if(is_double($value)){
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace SYSTEM\DB;
|
namespace SYSTEM\DB;
|
||||||
|
|
||||||
class ConnectionMYS extends ConnectionAbstr {
|
class ConnectionMYS extends ConnectionAbstr {
|
||||||
private $connection = NULL;
|
private $connection = NULL;
|
||||||
|
|
||||||
@ -43,13 +41,25 @@ class ConnectionMYS extends ConnectionAbstr {
|
|||||||
return mysqli_close($this->connection);}
|
return mysqli_close($this->connection);}
|
||||||
|
|
||||||
public function query($query){
|
public function query($query){
|
||||||
$result = mysqli_query($this->connection, $query);
|
$result = \mysqli_query($this->connection, $query);
|
||||||
if(!$result){
|
if(!$result){
|
||||||
throw new \Exception('Could not query Database. Check ur Query Syntax or required Rights: '.mysqli_error($this->connection));}
|
throw new \Exception('Could not query Database. Check ur Query Syntax or required Rights: '.\mysqli_error($this->connection));}
|
||||||
|
|
||||||
if($result === TRUE){
|
if($result === TRUE){
|
||||||
return TRUE;}
|
return TRUE;}
|
||||||
|
|
||||||
return new ResultMysqli($result);
|
return new ResultMysqli($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function commit(){
|
||||||
|
if(!\mysqli_commit($this->connection)){
|
||||||
|
throw new \Exception('Could not start Transaction: '.\mysqli_error($this->connection));}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function trans(){
|
||||||
|
if(!\mysqli_begin_transaction($this->connection,MYSQLI_TRANS_START_WITH_CONSISTENT_SNAPSHOT)){
|
||||||
|
throw new \Exception('Could not start Transaction: '.\mysqli_error($this->connection));}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
30
db/qq/QI.php
Normal file
30
db/qq/QI.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
namespace SYSTEM\DB;
|
||||||
|
class QI {
|
||||||
|
public static function QI($dbinfo = null){
|
||||||
|
if(!$dbinfo){
|
||||||
|
$dbinfo = \SYSTEM\system::getSystemDBInfo();}
|
||||||
|
|
||||||
|
if($dbinfo instanceof \SYSTEM\DB\DBInfoPG){
|
||||||
|
$files = static::files_pg();
|
||||||
|
} else if ($dbinfo instanceof \SYSTEM\DB\DBInfoMYS){
|
||||||
|
$files = static::files_mysql();
|
||||||
|
} else if ($dbinfo instanceof \SYSTEM\DB\DBInfoAMQP){
|
||||||
|
$files = static::files_amqp();
|
||||||
|
} else if ($dbinfo instanceof \SYSTEM\DB\DBInfoSQLite){
|
||||||
|
$files = static::files_sqlite();
|
||||||
|
} else {
|
||||||
|
throw new \SYSTEM\LOG\ERROR(static::get_class().' Could not understand Database Settings. Check ur Database Settings');}
|
||||||
|
|
||||||
|
$command = 'mysql'.
|
||||||
|
' --host=' . $dbinfo->m_host.
|
||||||
|
' --user=' . $dbinfo->m_user.
|
||||||
|
' --password=' . $dbinfo->m_password.
|
||||||
|
' --database=' . $dbinfo->m_database.
|
||||||
|
' --execute="SOURCE ';
|
||||||
|
$result = array();
|
||||||
|
foreach($files as $file){
|
||||||
|
$result[] = shell_exec($command .$file. '"');}
|
||||||
|
return \SYSTEM\LOG\JsonResult::toString($result);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,3 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
\SYSTEM\autoload::registerFolder(dirname(__FILE__).'/tbl','SYSTEM\DBD');
|
\SYSTEM\autoload::registerFolder(dirname(__FILE__).'/tbl','SYSTEM\DBD');
|
||||||
\SYSTEM\autoload::registerFolder(dirname(__FILE__).'/qq','SYSTEM\DBD');
|
\SYSTEM\autoload::registerFolder(dirname(__FILE__).'/qq','SYSTEM\DBD');
|
||||||
|
\SYSTEM\autoload::registerFolder(dirname(__FILE__).'/qt','SYSTEM\DBD');
|
||||||
10
dbd/qt/INSTALL_SAI.php
Normal file
10
dbd/qt/INSTALL_SAI.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
namespace SYSTEM\DBD;
|
||||||
|
class INSTALL_SAI extends \SYSTEM\DB\QI {
|
||||||
|
public static function get_class(){return \get_class();}
|
||||||
|
public static function files_mysql(){
|
||||||
|
return array(
|
||||||
|
\SYSTEM\SERVERPATH(new \SYSTEM\PSQL(),'sql/mysql/data/system_sai_api.sql')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -29,6 +29,11 @@ class PLIB extends PATH {
|
|||||||
return C_ROOT.\SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CONFIG_PATH_SYSTEMPATHREL).'lib/'.C_SUBPATH;}
|
return C_ROOT.\SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CONFIG_PATH_SYSTEMPATHREL).'lib/'.C_SUBPATH;}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class PSQL extends PATH {
|
||||||
|
static public function getPath(){
|
||||||
|
return C_ROOT.\SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CONFIG_PATH_SYSTEMPATHREL).'dbd/'.C_SUBPATH;}
|
||||||
|
}
|
||||||
|
|
||||||
function SERVERPATH(\SYSTEM\PATH $basepath, $subpath = ''){
|
function SERVERPATH(\SYSTEM\PATH $basepath, $subpath = ''){
|
||||||
return str_replace( array(C_ROOT,C_SUBPATH),
|
return str_replace( array(C_ROOT,C_SUBPATH),
|
||||||
array(\SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CONFIG_PATH_BASEPATH),$subpath),
|
array(\SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CONFIG_PATH_BASEPATH),$subpath),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user