#3 docu db
This commit is contained in:
parent
82dc71547c
commit
014da5c539
@ -1,10 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* System - PHP Framework
|
||||
*
|
||||
* PHP Version 5.6
|
||||
*
|
||||
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link https://github.com/webcraftmedia/system
|
||||
* @package SYSTEM\DB
|
||||
*/
|
||||
namespace SYSTEM\DB;
|
||||
|
||||
/**
|
||||
* Connection Class provided by System to open a Connection to a Database.
|
||||
*/
|
||||
class Connection extends ConnectionAbstr{
|
||||
//The open Connection
|
||||
/** ressource Variable to store then open Connection */
|
||||
private $connection = NULL;
|
||||
|
||||
//Connects to DB, dependent on DBInfo a connection will be established
|
||||
/**
|
||||
* Connect to the DB upon Construction.
|
||||
*
|
||||
* @param DBINFO $dbinfo Database Information Object or Null for default Connection
|
||||
*/
|
||||
public function __construct(DBInfo $dbinfo = null){
|
||||
if(!$dbinfo){
|
||||
$dbinfo = \SYSTEM\system::getSystemDBInfo();}
|
||||
@ -21,28 +39,62 @@ class Connection extends ConnectionAbstr{
|
||||
throw new \Exception('Could not understand Database Settings. Check ur Database Settings');}
|
||||
}
|
||||
|
||||
//Destruct connection object.
|
||||
/**
|
||||
* Destruct the Database Connection upon Destruction.
|
||||
*/
|
||||
public function __destruct(){
|
||||
unset($this->connection);}
|
||||
|
||||
//Query connected Database with prepared statements, $stmt = sql string with ?; $values = array of values
|
||||
/**
|
||||
* Close the Database Connection.
|
||||
*
|
||||
* @return bool Returns true or false depending on success
|
||||
*/
|
||||
public function close(){
|
||||
return $this->connection->close();}
|
||||
|
||||
/**
|
||||
* Query the Connection using Prepare Statement
|
||||
*
|
||||
* @param string $stmtName Name of the Statement - espec for PostgreSQL important
|
||||
* @param string $stmt SQL string of the Statement
|
||||
* @param array $values Array of Prepare Values
|
||||
* @return Result Returns Database Query Result.
|
||||
*/
|
||||
public function prepare($stmtName, $stmt, $values){
|
||||
return $this->connection->prepare($stmtName, $stmt, $values);}
|
||||
|
||||
//Close Connection
|
||||
public function close(){
|
||||
return $this->connection->close();}
|
||||
|
||||
//Query connected Database
|
||||
/**
|
||||
* Query the Connection using normal Query Statement
|
||||
*
|
||||
* @param string $query SQL string of the Statement
|
||||
* @return Result Returns Database Query Result.
|
||||
*/
|
||||
public function query($query){
|
||||
return $this->connection->query($query);}
|
||||
|
||||
|
||||
/**
|
||||
* Exec Query on Database
|
||||
*
|
||||
* @param string $query SQL string of the Statement
|
||||
* @return Result Returns Database Query Result.
|
||||
*/
|
||||
public function exec($query){
|
||||
return $this->connection->exec($query);}
|
||||
|
||||
/**
|
||||
* Open a Transaction on the Database Connection
|
||||
*
|
||||
* @return bool Returns true or false depending on success.
|
||||
*/
|
||||
public function trans(){
|
||||
return $this->connection->trans();}
|
||||
|
||||
/**
|
||||
* Commit a Transaction on the Database Connection
|
||||
*
|
||||
* @return bool Returns true or false depending on success.
|
||||
*/
|
||||
public function commit(){
|
||||
return $this->connection->commit();}
|
||||
}
|
||||
@ -1,11 +1,28 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* System - PHP Framework
|
||||
*
|
||||
* PHP Version 5.6
|
||||
*
|
||||
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link https://github.com/webcraftmedia/system
|
||||
* @package SYSTEM\DB
|
||||
*/
|
||||
namespace SYSTEM\DB;
|
||||
|
||||
/**
|
||||
* AMQP Connection Class provided by System to connect to AMQP Services.
|
||||
*/
|
||||
class ConnectionAMQP extends ConnectionAbstr {
|
||||
|
||||
/** ressource Variable to store then open Connection */
|
||||
private $connection = NULL;
|
||||
|
||||
/**
|
||||
* Connect to the DB upon Construction.
|
||||
*
|
||||
* @param DBINFO $dbinfo Database Information Object
|
||||
*/
|
||||
public function __construct(DBInfo $dbinfo){
|
||||
$this->connection = new \AMQPConnection(
|
||||
array(
|
||||
@ -22,6 +39,12 @@ class ConnectionAMQP extends ConnectionAbstr {
|
||||
throw new \SYSTEM\LOG\ERROR('Cannot connect to the amqp queue!');}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a Message to the AMQP Server
|
||||
*
|
||||
* @param array $msg Query Object
|
||||
* @return null Retuns null or trows an Error
|
||||
*/
|
||||
public function send($msg){
|
||||
$channel = new \AMQPChannel($this->connection);
|
||||
$exchange = new \AMQPExchange($channel);
|
||||
@ -45,22 +68,65 @@ class ConnectionAMQP extends ConnectionAbstr {
|
||||
$channel->commitTransaction();
|
||||
|
||||
if(!$message) {
|
||||
throw new \SYSTEM\LOG\ERROR("Error: Message '".$message."' was not sent to queue.!");
|
||||
}
|
||||
throw new \SYSTEM\LOG\ERROR("Error: Message '".$message."' was not sent to queue.!");}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destruct the Database Connection upon Destruction.
|
||||
*/
|
||||
public function __destruct(){
|
||||
$this->close();
|
||||
}
|
||||
$this->close();}
|
||||
|
||||
/**
|
||||
* Close the Database Connection.
|
||||
*
|
||||
* @return bool Returns true or false depending on success
|
||||
*/
|
||||
public function close(){
|
||||
if (!$this->connection->disconnect()) {
|
||||
throw new Exception("Could not disconnect !");
|
||||
}
|
||||
}
|
||||
return $this->connection->disconnect();}
|
||||
|
||||
public function query($query){ }
|
||||
/**
|
||||
* Query the Connection using normal Query Statement
|
||||
*
|
||||
* @param string $query SQL string of the Statement
|
||||
* @return Result Returns Database Query Result.
|
||||
*/
|
||||
public function query($query){
|
||||
throw new \Exception('Could not start Transaction: not implemented');}
|
||||
|
||||
public function prepare($stmtName, $stmt, $values){}
|
||||
/**
|
||||
* Query the Connection using Prepare Statement
|
||||
*
|
||||
* @param string $stmtName Name of the Statement - espec for PostgreSQL important
|
||||
* @param string $stmt SQL string of the Statement
|
||||
* @param array $values Array of Prepare Values
|
||||
* @return Result Returns Database Query Result.
|
||||
*/
|
||||
public function prepare($stmtName, $stmt, $values){
|
||||
throw new \Exception('Could not start Transaction: not implemented');}
|
||||
|
||||
/**
|
||||
* Commit a Transaction on the Database Connection
|
||||
*
|
||||
* @return bool Returns true or false depending on success.
|
||||
*/
|
||||
public function commit(){
|
||||
throw new \Exception('Could not start Transaction: not implemented');}
|
||||
|
||||
/**
|
||||
* Exec Query on Database
|
||||
*
|
||||
* @param string $query SQL string of the Statement
|
||||
* @return Result Returns Database Query Result.
|
||||
*/
|
||||
public function exec($query){
|
||||
throw new \Exception('Could not start Transaction: not implemented');}
|
||||
|
||||
/**
|
||||
* Open a Transaction on the Database Connection
|
||||
*
|
||||
* @return bool Returns true or false depending on success.
|
||||
*/
|
||||
public function trans(){
|
||||
throw new \Exception('Could not start Transaction: not implemented');}
|
||||
}
|
||||
@ -1,29 +1,89 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* System - PHP Framework
|
||||
*
|
||||
* PHP Version 5.6
|
||||
*
|
||||
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link https://github.com/webcraftmedia/system
|
||||
* @package SYSTEM\DB
|
||||
*/
|
||||
namespace SYSTEM\DB;
|
||||
|
||||
/**
|
||||
* Abstract Connection Class provided by System as a PDO Controller.
|
||||
*/
|
||||
abstract class ConnectionAbstr {
|
||||
//Connects to Database with given DBInfos
|
||||
/**
|
||||
* Connect to the DB upon Construction.
|
||||
*
|
||||
* @param DBINFO $dbinfo Database Information Object
|
||||
*/
|
||||
abstract public function __construct(DBInfo $dbinfo);
|
||||
//Close Connection to Database
|
||||
|
||||
/**
|
||||
* Destruct the Database Connection upon Destruction.
|
||||
*/
|
||||
abstract public function __destruct();
|
||||
//Close Connection to Database
|
||||
|
||||
/**
|
||||
* Close the Database Connection.
|
||||
*
|
||||
* @return bool Returns true or false depending on success
|
||||
*/
|
||||
abstract public function close();
|
||||
//Query Database with prepared Statement with $stmtName = name of the stament(pg only) $stmt = string and $values = array()
|
||||
|
||||
/**
|
||||
* Query the Connection using Prepare Statement
|
||||
*
|
||||
* @param string $stmtName Name of the Statement - espec for PostgreSQL important
|
||||
* @param string $stmt SQL string of the Statement
|
||||
* @param array $values Array of Prepare Values
|
||||
* @return Result Returns Database Query Result.
|
||||
*/
|
||||
abstract public function prepare($stmtName, $stmt, $values);
|
||||
//Query Database with normal Statement with $query = SQLString
|
||||
|
||||
/**
|
||||
* Query the Connection using normal Query Statement
|
||||
*
|
||||
* @param string $query SQL string of the Statement
|
||||
* @return Result Returns Database Query Result.
|
||||
*/
|
||||
abstract public function query($query);
|
||||
abstract public function commit();
|
||||
|
||||
/**
|
||||
* Exec Query on Database
|
||||
*
|
||||
* @param string $query SQL string of the Statement
|
||||
* @return Result Returns Database Query Result.
|
||||
*/
|
||||
abstract public function exec($query);
|
||||
|
||||
/**
|
||||
* Open a Transaction on the Database Connection
|
||||
*
|
||||
* @return bool Returns true or false depending on success.
|
||||
*/
|
||||
abstract public function trans();
|
||||
//Convert Prepared Values to SQL Type identifiers
|
||||
|
||||
/**
|
||||
* Commit a Transaction on the Database Connection
|
||||
*
|
||||
* @return bool Returns true or false depending on success.
|
||||
*/
|
||||
abstract public function commit();
|
||||
|
||||
/**
|
||||
* Helperfunction to convert Prepared Values to SQL Type identifiers
|
||||
*
|
||||
* @param string $value Value to be examined regarding Type
|
||||
* @return string Returns d,i,s or b depending on the values type.
|
||||
*/
|
||||
protected static function getPrepareValueType($value){
|
||||
if(is_double($value)){
|
||||
return 'd';}
|
||||
if(is_integer($value)){
|
||||
return 'i';}
|
||||
if(is_string($value)){
|
||||
return 's';}
|
||||
//blob
|
||||
return 'b';
|
||||
if(is_double($value)){return 'd';}
|
||||
if(is_integer($value)){return 'i';}
|
||||
if(is_string($value)){return 's';}
|
||||
return 'b';//blob
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* System - PHP Framework
|
||||
*
|
||||
* PHP Version 5.6
|
||||
*
|
||||
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link https://github.com/webcraftmedia/system
|
||||
* @package SYSTEM\DB
|
||||
*/
|
||||
namespace SYSTEM\DB;
|
||||
|
||||
/**
|
||||
* MYSQL Connection Class provided by System to connect to MYSQL Database.
|
||||
*/
|
||||
class ConnectionMYS extends ConnectionAbstr {
|
||||
/** ressource Variable to store then open Connection */
|
||||
private $connection = NULL;
|
||||
|
||||
/**
|
||||
* Connect to the DB upon Construction.
|
||||
*
|
||||
* @param DBINFO $dbinfo Database Information Object
|
||||
* @param bool $new_link Force new Connection
|
||||
* @param int $client_flag Client Flag transmitted on connection
|
||||
*/
|
||||
public function __construct(DBInfo $dbinfo, $new_link = false, $client_flag = 0){
|
||||
$this->connection = @mysqli_connect($dbinfo->m_host, $dbinfo->m_user, $dbinfo->m_password, $new_link, $client_flag);
|
||||
if(!$this->connection){
|
||||
@ -15,9 +37,28 @@ class ConnectionMYS extends ConnectionAbstr {
|
||||
\mysqli_set_charset($this->connection, 'utf8');
|
||||
}
|
||||
|
||||
/**
|
||||
* Destruct the Database Connection upon Destruction.
|
||||
*/
|
||||
public function __destruct(){
|
||||
$this->close();}
|
||||
|
||||
/**
|
||||
* Close the Database Connection.
|
||||
*
|
||||
* @return bool Returns true or false depending on success
|
||||
*/
|
||||
public function close(){
|
||||
return mysqli_close($this->connection);}
|
||||
|
||||
/**
|
||||
* Query the Connection using Prepare Statement
|
||||
*
|
||||
* @param string $stmtName Name of the Statement - espec for PostgreSQL important
|
||||
* @param string $stmt SQL string of the Statement
|
||||
* @param array $values Array of Prepare Values
|
||||
* @return Result Returns Database Query Result.
|
||||
*/
|
||||
public function prepare($stmtName, $stmt, $values){
|
||||
$prepStmt = \mysqli_prepare($this->connection, $stmt);
|
||||
if(!$prepStmt){
|
||||
@ -37,29 +78,45 @@ class ConnectionMYS extends ConnectionAbstr {
|
||||
return new ResultMysqliPrepare($prepStmt,$this);
|
||||
}
|
||||
|
||||
public function close(){
|
||||
return mysqli_close($this->connection);}
|
||||
|
||||
/**
|
||||
* Query the Connection using normal Query Statement
|
||||
*
|
||||
* @param string $query SQL string of the Statement
|
||||
* @return Result Returns Database Query Result.
|
||||
*/
|
||||
public function query($query){
|
||||
$result = \mysqli_query($this->connection, $query);
|
||||
if(!$result){
|
||||
throw new \Exception('Could not query Database. Check ur Query Syntax or required Rights: '.\mysqli_error($this->connection));}
|
||||
|
||||
if($result === TRUE){
|
||||
return TRUE;}
|
||||
|
||||
return new ResultMysqli($result);
|
||||
return $result === true ? $result : new ResultMysqli($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exec Query on Database
|
||||
*
|
||||
* @param string $query SQL string of the Statement
|
||||
* @return Result Returns Database Query Result.
|
||||
*/
|
||||
public function exec($query){
|
||||
throw new \Exception('Could not start Transaction: not implemented');}
|
||||
|
||||
/**
|
||||
* Commit a Transaction on the Database Connection
|
||||
*
|
||||
* @return bool Returns true or false depending on success.
|
||||
*/
|
||||
public function commit(){
|
||||
if(!\mysqli_commit($this->connection)){
|
||||
throw new \Exception('Could not start Transaction: '.\mysqli_error($this->connection));}
|
||||
return true;
|
||||
}
|
||||
return true;}
|
||||
|
||||
/**
|
||||
* Open a Transaction on the Database Connection
|
||||
*
|
||||
* @return bool Returns true or false depending on success.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
return true;}
|
||||
}
|
||||
@ -1,23 +1,56 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* System - PHP Framework
|
||||
*
|
||||
* PHP Version 5.6
|
||||
*
|
||||
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link https://github.com/webcraftmedia/system
|
||||
* @package SYSTEM\DB
|
||||
*/
|
||||
namespace SYSTEM\DB;
|
||||
|
||||
/**
|
||||
* PostgreSQL Connection Class provided by System to connect to PostgreSQL Database.
|
||||
*/
|
||||
class ConnectionPG extends ConnectionAbstr {
|
||||
|
||||
/** ressource Variable to store then open Connection */
|
||||
private $connection = NULL;
|
||||
//private $dbinfo = NULL;
|
||||
|
||||
/**
|
||||
* Connect to the DB upon Construction.
|
||||
*
|
||||
* @param DBINFO $dbinfo Database Information Object
|
||||
*/
|
||||
public function __construct(DBInfo $dbinfo){
|
||||
//$this->dbinfo = $dbinfo;
|
||||
|
||||
$this->connection = pg_connect("host=".$dbinfo->m_host." port=".$dbinfo->m_port." dbname=".$dbinfo->m_database."
|
||||
user=".$dbinfo->m_user." password=".$dbinfo->m_password."");
|
||||
if(!$this->connection){
|
||||
throw new \Exception('Could not connect to Database. Check ur Database Settings');}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destruct the Database Connection upon Destruction.
|
||||
*/
|
||||
public function __destruct(){}
|
||||
|
||||
/**
|
||||
* Close the Database Connection.
|
||||
*
|
||||
* @return bool Returns true or false depending on success
|
||||
*/
|
||||
public function close(){
|
||||
return pg_close($this->connection);}
|
||||
|
||||
/**
|
||||
* Query the Connection using Prepare Statement
|
||||
*
|
||||
* @param string $stmtName Name of the Statement - espec for PostgreSQL important
|
||||
* @param string $stmt SQL string of the Statement
|
||||
* @param array $values Array of Prepare Values
|
||||
* @return Result Returns Database Query Result.
|
||||
*/
|
||||
public function prepare($stmtName, $stmt, $values){
|
||||
$result = pg_query_params($this->connection, 'SELECT name FROM pg_prepared_statements WHERE name = $1', array($stmtName));
|
||||
//var_dump($stmt);
|
||||
@ -41,9 +74,12 @@ class ConnectionPG extends ConnectionAbstr {
|
||||
return new ResultPostgres($result,$this);
|
||||
}
|
||||
|
||||
public function close(){
|
||||
return pg_close($this->connection);}
|
||||
|
||||
/**
|
||||
* Query the Connection using normal Query Statement
|
||||
*
|
||||
* @param string $query SQL string of the Statement
|
||||
* @return Result Returns Database Query Result.
|
||||
*/
|
||||
public function query($query){
|
||||
$result = \pg_query($this->connection, $query);
|
||||
if(($info = \pg_last_notice($this->connection)) != ''){
|
||||
@ -58,10 +94,28 @@ class ConnectionPG extends ConnectionAbstr {
|
||||
return new ResultPostgres($result,$this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a Transaction on the Database Connection
|
||||
*
|
||||
* @return bool Returns true or false depending on success.
|
||||
*/
|
||||
public function trans(){
|
||||
return $this->connection->trans();}
|
||||
|
||||
/**
|
||||
* Commit a Transaction on the Database Connection
|
||||
*
|
||||
* @return bool Returns true or false depending on success.
|
||||
*/
|
||||
public function commit(){
|
||||
return $this->connection->commit();}
|
||||
|
||||
/**
|
||||
* Exec Query on Database
|
||||
*
|
||||
* @param string $query SQL string of the Statement
|
||||
* @return Result Returns Database Query Result.
|
||||
*/
|
||||
public function exec($query) {
|
||||
throw new \Exception('Could not start Transaction: not implemented');}
|
||||
}
|
||||
@ -1,20 +1,57 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* System - PHP Framework
|
||||
*
|
||||
* PHP Version 5.6
|
||||
*
|
||||
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link https://github.com/webcraftmedia/system
|
||||
* @package SYSTEM\DB
|
||||
*/
|
||||
namespace SYSTEM\DB;
|
||||
|
||||
/**
|
||||
* SQLite Connection Class provided by System to connect to SQLite Databasefile.
|
||||
*/
|
||||
class ConnectionSQLite extends ConnectionAbstr {
|
||||
/** ressource Variable to store the open Connection */
|
||||
private $connection = NULL;
|
||||
|
||||
public function __construct(DBInfo $dbinfo, $new_link = false, $client_flag = 0){
|
||||
/**
|
||||
* Connect to the DB upon Construction.
|
||||
*
|
||||
* @param DBINFO $dbinfo Database Information Object
|
||||
*/
|
||||
public function __construct(DBInfo $dbinfo){
|
||||
$error = null;
|
||||
$this->connection = new \SQLite3($dbinfo->m_database);
|
||||
if(!$this->connection){
|
||||
throw new \Exception('Could not connect to Database. Check ur Database Settings: '.$error);}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destruct the Database Connection upon Destruction.
|
||||
*/
|
||||
public function __destruct(){
|
||||
$this->close();}
|
||||
|
||||
/**
|
||||
* Close the Database Connection.
|
||||
*
|
||||
* @return bool Returns true or false depending on success
|
||||
*/
|
||||
public function close(){
|
||||
return $this->connection->close();}
|
||||
|
||||
/**
|
||||
* Query the Connection using Prepare Statement
|
||||
*
|
||||
* @param string $stmtName Name of the Statement - espec for PostgreSQL important
|
||||
* @param string $stmt SQL string of the Statement
|
||||
* @param array $values Array of Prepare Values
|
||||
* @return Result Returns Database Query Result.
|
||||
*/
|
||||
public function prepare($stmtName, $stmt, $values){
|
||||
$prepStmt = $this->connection->prepare($stmt);
|
||||
if(!$prepStmt){
|
||||
@ -29,9 +66,12 @@ class ConnectionSQLite extends ConnectionAbstr {
|
||||
return new ResultSQLite($result,$prepStmt);
|
||||
}
|
||||
|
||||
public function close(){
|
||||
return $this->connection->close();}
|
||||
|
||||
/**
|
||||
* Query the Connection using normal Query Statement
|
||||
*
|
||||
* @param string $query SQL string of the Statement
|
||||
* @return Result Returns Database Query Result.
|
||||
*/
|
||||
public function query($query){
|
||||
$result = $this->connection->query($query);
|
||||
if(!$result){
|
||||
@ -42,13 +82,28 @@ class ConnectionSQLite extends ConnectionAbstr {
|
||||
return new ResultSQLite($result,null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exec Query on Database
|
||||
*
|
||||
* @param string $query SQL string of the Statement
|
||||
* @return Result Returns Database Query Result.
|
||||
*/
|
||||
public function exec($query){
|
||||
return $this->connection->exec($query);
|
||||
}
|
||||
return $this->connection->exec($query);}
|
||||
|
||||
/**
|
||||
* Commit a Transaction on the Database Connection
|
||||
*
|
||||
* @return bool Returns true or false depending on success.
|
||||
*/
|
||||
public function commit(){
|
||||
throw new \Exception('Could not start Transaction: not implemented');}
|
||||
|
||||
/**
|
||||
* Open a Transaction on the Database Connection
|
||||
*
|
||||
* @return bool Returns true or false depending on success.
|
||||
*/
|
||||
public function trans(){
|
||||
throw new \Exception('Could not start Transaction: not implemented');}
|
||||
}
|
||||
@ -1,13 +1,39 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* System - PHP Framework
|
||||
*
|
||||
* PHP Version 5.6
|
||||
*
|
||||
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link https://github.com/webcraftmedia/system
|
||||
* @package SYSTEM\DB
|
||||
*/
|
||||
namespace SYSTEM\DB;
|
||||
|
||||
/**
|
||||
* DBInfo Abstract Class provided by System to hold Database Information.
|
||||
*/
|
||||
abstract class DBInfo {
|
||||
/** string Variable to store Database name */
|
||||
public $m_database = null;
|
||||
/** string Variable to store Database user */
|
||||
public $m_user = null;
|
||||
/** string Variable to store Database password */
|
||||
public $m_password = null;
|
||||
/** string Variable to store Database host */
|
||||
public $m_host = null;
|
||||
/** int Variable to store Database port */
|
||||
public $m_port = null;
|
||||
|
||||
/**
|
||||
* Store Data upon Construction.
|
||||
*
|
||||
* @param string $database Database name
|
||||
* @param string $user Database user
|
||||
* @param string $password Database password
|
||||
* @param string $host Database host
|
||||
* @param int $port Database port
|
||||
*/
|
||||
abstract public function __construct($database , $user , $password, $host, $port = null);
|
||||
}
|
||||
@ -1,8 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* System - PHP Framework
|
||||
*
|
||||
* PHP Version 5.6
|
||||
*
|
||||
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link https://github.com/webcraftmedia/system
|
||||
* @package SYSTEM\DB
|
||||
*/
|
||||
namespace SYSTEM\DB;
|
||||
|
||||
/**
|
||||
* DBInfoAMQP Class provided by System to hold AMQP Database Information.
|
||||
*/
|
||||
class DBInfoAMQP extends \SYSTEM\DB\DBInfo {
|
||||
|
||||
/**
|
||||
* Store Data upon Construction.
|
||||
*
|
||||
* @param string $database Database name
|
||||
* @param string $user Database user
|
||||
* @param string $password Database password
|
||||
* @param string $host Database host
|
||||
* @param int $port Database port
|
||||
*/
|
||||
public function __construct($vhost , $user , $password, $host, $port = null){
|
||||
$this->m_database = $vhost;
|
||||
$this->m_user = $user;
|
||||
|
||||
@ -1,8 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* System - PHP Framework
|
||||
*
|
||||
* PHP Version 5.6
|
||||
*
|
||||
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link https://github.com/webcraftmedia/system
|
||||
* @package SYSTEM\DB
|
||||
*/
|
||||
namespace SYSTEM\DB;
|
||||
|
||||
/**
|
||||
* DBInfoMYS Class provided by System to hold MYSQL Database Information.
|
||||
*/
|
||||
class DBInfoMYS extends \SYSTEM\DB\DBInfo {
|
||||
|
||||
/**
|
||||
* Store Data upon Construction.
|
||||
*
|
||||
* @param string $database Database name
|
||||
* @param string $user Database user
|
||||
* @param string $password Database password
|
||||
* @param string $host Database host
|
||||
* @param int $port Database port
|
||||
*/
|
||||
public function __construct($database , $user , $password, $host, $port = null){
|
||||
$this->m_database = $database;
|
||||
$this->m_user = $user;
|
||||
|
||||
@ -1,8 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* System - PHP Framework
|
||||
*
|
||||
* PHP Version 5.6
|
||||
*
|
||||
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link https://github.com/webcraftmedia/system
|
||||
* @package SYSTEM\DB
|
||||
*/
|
||||
namespace SYSTEM\DB;
|
||||
|
||||
/**
|
||||
* DBInfoPG Class provided by System to hold PostgreSQL Database Information.
|
||||
*/
|
||||
class DBInfoPG extends \SYSTEM\DB\DBInfo {
|
||||
|
||||
/**
|
||||
* Store Data upon Construction.
|
||||
*
|
||||
* @param string $database Database name
|
||||
* @param string $user Database user
|
||||
* @param string $password Database password
|
||||
* @param string $host Database host
|
||||
* @param int $port Database port
|
||||
*/
|
||||
public function __construct($database , $user , $password, $host, $port = null){
|
||||
$this->m_database = $database;
|
||||
$this->m_user = $user;
|
||||
|
||||
@ -1,7 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* System - PHP Framework
|
||||
*
|
||||
* PHP Version 5.6
|
||||
*
|
||||
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link https://github.com/webcraftmedia/system
|
||||
* @package SYSTEM\DB
|
||||
*/
|
||||
namespace SYSTEM\DB;
|
||||
|
||||
/**
|
||||
* DBInfoSQLite Class provided by System to hold SQLite File-Database Information.
|
||||
*/
|
||||
class DBInfoSQLite extends \SYSTEM\DB\DBInfo {
|
||||
/**
|
||||
* Store Data upon Construction.
|
||||
*
|
||||
* @param string $database Database name
|
||||
* @param string $user Database user
|
||||
* @param string $password Database password
|
||||
* @param string $host Database host
|
||||
* @param int $port Database port
|
||||
*/
|
||||
public function __construct($database , $user = null , $password = null, $host = null, $port = null){
|
||||
$this->m_database = $database;
|
||||
$this->m_user = $user;
|
||||
|
||||
23
db/qq/QI.php
23
db/qq/QI.php
@ -1,6 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* System - PHP Framework
|
||||
*
|
||||
* PHP Version 5.6
|
||||
*
|
||||
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link https://github.com/webcraftmedia/system
|
||||
* @package SYSTEM\DB
|
||||
*/
|
||||
namespace SYSTEM\DB;
|
||||
class QI {
|
||||
|
||||
/**
|
||||
* QI Class provided by System to execute quick installation statements.
|
||||
*/
|
||||
class QI {
|
||||
/**
|
||||
* Executes stored action by calling either files_pgsql() or files_mysql()
|
||||
* of inherting class
|
||||
*
|
||||
* @param DBINFO $dbinfo Database Info or Null for Default DB
|
||||
* @return array Returns array with Files and execution results
|
||||
*/
|
||||
public static function QI($dbinfo = null){
|
||||
if(!$dbinfo){
|
||||
$dbinfo = \SYSTEM\system::getSystemDBInfo();}
|
||||
|
||||
42
db/qq/QP.php
42
db/qq/QP.php
@ -1,7 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* System - PHP Framework
|
||||
*
|
||||
* PHP Version 5.6
|
||||
*
|
||||
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link https://github.com/webcraftmedia/system
|
||||
* @package SYSTEM\DB
|
||||
*/
|
||||
namespace SYSTEM\DB;
|
||||
|
||||
/**
|
||||
* QQ Class provided by System to execute quick prepare statements.
|
||||
*/
|
||||
class QP {
|
||||
/**
|
||||
* Executes stored action and return Database Object
|
||||
*
|
||||
* @param array $params Parameter passed to the prepare-query
|
||||
* @param DBINFO $dbinfo Database Info or Null for Default DB
|
||||
* @return Result Returns Database Result Object
|
||||
*/
|
||||
public static function QQ($params,$dbinfo = null){
|
||||
if(!$dbinfo){
|
||||
$dbinfo = \SYSTEM\system::getSystemDBInfo();}
|
||||
@ -29,6 +49,13 @@ class QP {
|
||||
throw new \Exception('Could not understand Database Settings. Check ur Database Settings');
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes stored action and return all Data found
|
||||
*
|
||||
* @param array $params Parameter passed to the prepare-query
|
||||
* @param DBINFO $dbinfo Database Info or Null for Default DB
|
||||
* @return array Returns array with all lines of Database Query
|
||||
*/
|
||||
public static function QA($params,$dbinfo = null){
|
||||
$res = self::QQ($params,$dbinfo);
|
||||
$result = array();
|
||||
@ -37,9 +64,24 @@ class QP {
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes stored action and return one line of Data found
|
||||
*
|
||||
* @param array $params Parameter passed to the prepare-query
|
||||
* @param DBINFO $dbinfo Database Info or Null for Default DB
|
||||
* @return array Returns array with all field of one lines of the Database Query
|
||||
*/
|
||||
public static function Q1($params,$dbinfo = null){
|
||||
return self::QQ($params,$dbinfo)->next();}
|
||||
|
||||
/**
|
||||
* Executes stored action and return Database Result Object.
|
||||
* Use this function if the Result is either true or false (update/delete/insert)
|
||||
*
|
||||
* @param array $params Parameter passed to the prepare-query
|
||||
* @param DBINFO $dbinfo Database Info or Null for Default DB
|
||||
* @return bool Returns true or false (or Result if used incorrectly)
|
||||
*/
|
||||
public static function QI($params,$dbinfo = null){
|
||||
$qq = self::QQ($params,$dbinfo);
|
||||
return $qq->affectedRows() != (0||null);}
|
||||
|
||||
41
db/qq/QQ.php
41
db/qq/QQ.php
@ -1,7 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* System - PHP Framework
|
||||
*
|
||||
* PHP Version 5.6
|
||||
*
|
||||
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link https://github.com/webcraftmedia/system
|
||||
* @package SYSTEM\DB
|
||||
*/
|
||||
namespace SYSTEM\DB;
|
||||
|
||||
class QQ {
|
||||
/**
|
||||
* QQ Class provided by System to execute quick query statements.
|
||||
*/
|
||||
class QQ {
|
||||
/**
|
||||
* Executes stored action and return Database Object
|
||||
*
|
||||
* @param DBINFO $dbinfo Database Info or Null for Default DB
|
||||
* @return Result Returns Database Result Object
|
||||
*/
|
||||
public static function QQ($dbinfo = null){
|
||||
if(!$dbinfo){
|
||||
$dbinfo = \SYSTEM\system::getSystemDBInfo();}
|
||||
@ -31,6 +50,12 @@ class QQ {
|
||||
throw new \Exception('Could not understand Database Settings. Check ur Database Settings');
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes stored action and return all Data found
|
||||
*
|
||||
* @param DBINFO $dbinfo Database Info or Null for Default DB
|
||||
* @return array Returns array with all lines of Database Query
|
||||
*/
|
||||
public static function QA($dbinfo = null){
|
||||
$res = self::QQ($dbinfo);
|
||||
$result = array();
|
||||
@ -39,8 +64,22 @@ class QQ {
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes stored action and return one line of Data found
|
||||
*
|
||||
* @param DBINFO $dbinfo Database Info or Null for Default DB
|
||||
* @return array Returns array with all field of one lines of the Database Query
|
||||
*/
|
||||
public static function Q1($dbinfo = null){
|
||||
return self::QQ($dbinfo)->next();}
|
||||
|
||||
/**
|
||||
* Executes stored action and return Database Result Object.
|
||||
* Use this function if the Result is either true or false (update/delete/insert)
|
||||
*
|
||||
* @param DBINFO $dbinfo Database Info or Null for Default DB
|
||||
* @return bool Returns true or false (or Result if used incorrectly)
|
||||
*/
|
||||
public static function QI($dbinfo = null){
|
||||
return self::QQ($dbinfo);}
|
||||
}
|
||||
@ -1,16 +1,54 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* System - PHP Framework
|
||||
*
|
||||
* PHP Version 5.6
|
||||
*
|
||||
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link https://github.com/webcraftmedia/system
|
||||
* @package SYSTEM\DB
|
||||
*/
|
||||
namespace SYSTEM\DB;
|
||||
|
||||
/**
|
||||
* Result Class provided by System to hold Database Query Result Ressources.
|
||||
*/
|
||||
abstract class Result {
|
||||
|
||||
/**
|
||||
* Counts the Lines in the Resultset
|
||||
*
|
||||
* @return int Returns number of lines in the result
|
||||
*/
|
||||
public abstract function count();
|
||||
|
||||
/**
|
||||
* Counts the affected lines in the Resultset
|
||||
*
|
||||
* @return int Returns number of affected lines in the result
|
||||
*/
|
||||
public abstract function affectedRows();
|
||||
|
||||
/**
|
||||
* Returns the next line in the Resultset
|
||||
*
|
||||
* @param bool $object Determines if the result will be an object or array
|
||||
* @return array Returns an array(object) containing the next line
|
||||
*/
|
||||
public abstract function next($object = false);
|
||||
|
||||
/**
|
||||
* Seeks an amount of lines within the Resultset
|
||||
*
|
||||
* @param int $row_number Lines to seek over
|
||||
* @return bool Returns true or false
|
||||
*/
|
||||
public abstract function seek($row_number);
|
||||
|
||||
/**
|
||||
* Closes the Resultset
|
||||
*
|
||||
* @return null Returns null
|
||||
*/
|
||||
public abstract function close();
|
||||
}
|
||||
@ -1,28 +1,68 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* System - PHP Framework
|
||||
*
|
||||
* PHP Version 5.6
|
||||
*
|
||||
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link https://github.com/webcraftmedia/system
|
||||
* @package SYSTEM\DB
|
||||
*/
|
||||
namespace SYSTEM\DB;
|
||||
|
||||
/**
|
||||
* Result Class provided by System to hold Database Query Result Ressources of AMQP Querys.
|
||||
*/
|
||||
class ResultAMQP extends \SYSTEM\DB\Result{ // < maybe not ? check if amqpchannel is compatible with dbresult.
|
||||
|
||||
/** ressource Variable to store Database Result-ressource */
|
||||
private $res = NULL;
|
||||
/** ressource Variable to store current Line either as array or object */
|
||||
private $current = NULL;
|
||||
|
||||
//Result from mysql_query
|
||||
/**
|
||||
* Construct the Resultset with a database ressource
|
||||
*/
|
||||
public function __construct($res){
|
||||
$this->res = $res;}
|
||||
|
||||
/**
|
||||
* Close Resultset upon destruction
|
||||
*/
|
||||
public function __destruct(){
|
||||
$this->close();}
|
||||
|
||||
/**
|
||||
* Closes the Resultset
|
||||
*
|
||||
* @return null Returns null
|
||||
*/
|
||||
public function close(){
|
||||
pg_free_result($this->res);}
|
||||
|
||||
/**
|
||||
* Counts the Lines in the Resultset
|
||||
*
|
||||
* @return int Returns number of lines in the result
|
||||
*/
|
||||
public function count(){
|
||||
return pg_num_rows($this->res);}
|
||||
|
||||
/**
|
||||
* Counts the affected lines in the Resultset
|
||||
*
|
||||
* @return int Returns number of affected lines in the result
|
||||
*/
|
||||
public function affectedRows(){
|
||||
throw new \SYSTEM\LOG\ERROR("Not Supported!");}
|
||||
|
||||
/**
|
||||
* Returns the next line in the Resultset
|
||||
*
|
||||
* @param bool $object Determines if the result will be an object or array
|
||||
* @param int $result_type Mysql Fetch result Type
|
||||
* @return array Returns an array(object) containing the next line
|
||||
*/
|
||||
public function next($object = false, $result_type = MYSQL_BOTH){
|
||||
if($object){
|
||||
$this->current = pg_fetch_object($this->res);
|
||||
@ -32,6 +72,12 @@ class ResultAMQP extends \SYSTEM\DB\Result{ // < maybe not ? check if amqpchanne
|
||||
return $this->current;
|
||||
}
|
||||
|
||||
/**
|
||||
* Seeks an amount of lines within the Resultset
|
||||
*
|
||||
* @param int $row_number Lines to seek over
|
||||
* @return bool Returns true or false
|
||||
*/
|
||||
public function seek($row_number){
|
||||
return pg_data_seek($this->res,$row_number);}
|
||||
}
|
||||
@ -1,28 +1,68 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* System - PHP Framework
|
||||
*
|
||||
* PHP Version 5.6
|
||||
*
|
||||
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link https://github.com/webcraftmedia/system
|
||||
* @package SYSTEM\DB
|
||||
*/
|
||||
namespace SYSTEM\DB;
|
||||
|
||||
/**
|
||||
* Result Class provided by System to hold Database Query Result Ressources of MYSQL Querys.
|
||||
*/
|
||||
class ResultMysqli extends \SYSTEM\DB\Result{
|
||||
|
||||
/** ressource Variable to store Database Result-ressource */
|
||||
private $res = NULL;
|
||||
/** ressource Variable to store current Line either as array or object */
|
||||
private $current = NULL;
|
||||
|
||||
//Result from mysql_query
|
||||
/**
|
||||
* Construct the Resultset with a database ressource
|
||||
*/
|
||||
public function __construct($res){
|
||||
$this->res = $res;}
|
||||
|
||||
/**
|
||||
* Close Resultset upon destruction
|
||||
*/
|
||||
public function __destruct(){
|
||||
$this->close();}
|
||||
|
||||
/**
|
||||
* Closes the Resultset
|
||||
*
|
||||
* @return null Returns null
|
||||
*/
|
||||
public function close(){
|
||||
mysqli_free_result($this->res);}
|
||||
|
||||
/**
|
||||
* Counts the Lines in the Resultset
|
||||
*
|
||||
* @return int Returns number of lines in the result
|
||||
*/
|
||||
public function count(){
|
||||
return mysqli_num_rows($this->res);}
|
||||
|
||||
/**
|
||||
* Counts the affected lines in the Resultset
|
||||
*
|
||||
* @return int Returns number of affected lines in the result
|
||||
*/
|
||||
public function affectedRows(){
|
||||
return mysqli_affected_rows($this->res);}
|
||||
|
||||
/**
|
||||
* Returns the next line in the Resultset
|
||||
*
|
||||
* @param bool $object Determines if the result will be an object or array
|
||||
* @param int $result_type Mysql Fetch result Type
|
||||
* @return array Returns an array(object) containing the next line
|
||||
*/
|
||||
public function next($object = false, $result_type = MYSQL_BOTH){
|
||||
if($object){
|
||||
$this->current = mysqli_fetch_object($this->res);
|
||||
@ -32,6 +72,12 @@ class ResultMysqli extends \SYSTEM\DB\Result{
|
||||
return $this->current;
|
||||
}
|
||||
|
||||
/**
|
||||
* Seeks an amount of lines within the Resultset
|
||||
*
|
||||
* @param int $row_number Lines to seek over
|
||||
* @return bool Returns true or false
|
||||
*/
|
||||
public function seek($row_number){
|
||||
return mysqli_data_seek($this->res,$row_number);}
|
||||
}
|
||||
@ -1,15 +1,32 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* System - PHP Framework
|
||||
*
|
||||
* PHP Version 5.6
|
||||
*
|
||||
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link https://github.com/webcraftmedia/system
|
||||
* @package SYSTEM\DB
|
||||
*/
|
||||
namespace SYSTEM\DB;
|
||||
|
||||
/**
|
||||
* Result Class provided by System to hold Database Query Result Ressources of MYSQL prepare Querys.
|
||||
*/
|
||||
class ResultMysqliPrepare extends \SYSTEM\DB\Result{
|
||||
|
||||
/** ressource Variable to store Database Result-ressource */
|
||||
private $res = NULL;
|
||||
/** ressource Variable to store Metadata of Colums */
|
||||
private $meta = NULL;
|
||||
/** ressource Variable to store Binding Variables */
|
||||
private $binds = array();
|
||||
/** ressource Variable to store Database Connection */
|
||||
private $connection = NULL;
|
||||
|
||||
//Result from mysql_query
|
||||
/**
|
||||
* Construct the Resultset with a database ressource
|
||||
*/
|
||||
public function __construct($res,$connection){
|
||||
$this->res = $res;
|
||||
$this->connection = $connection;
|
||||
@ -30,22 +47,44 @@ class ResultMysqliPrepare extends \SYSTEM\DB\Result{
|
||||
$this->res->store_result();
|
||||
}
|
||||
|
||||
/**
|
||||
* Close Resultset upon destruction
|
||||
*/
|
||||
public function __destruct() {
|
||||
$this->close();}
|
||||
|
||||
/**
|
||||
* Closes the Resultset
|
||||
*
|
||||
* @return null Returns null
|
||||
*/
|
||||
public function close(){
|
||||
mysqli_stmt_free_result($this->res);
|
||||
mysqli_stmt_close($this->res);
|
||||
}
|
||||
return mysqli_stmt_close($this->res);}
|
||||
|
||||
/**
|
||||
* Counts the Lines in the Resultset
|
||||
*
|
||||
* @return int Returns number of lines in the result
|
||||
*/
|
||||
public function count(){
|
||||
return \mysqli_stmt_num_rows($this->res);}
|
||||
|
||||
/**
|
||||
* Counts the affected lines in the Resultset
|
||||
*
|
||||
* @return int Returns number of affected lines in the result
|
||||
*/
|
||||
public function affectedRows(){
|
||||
return \mysqli_stmt_affected_rows($this->res);}
|
||||
|
||||
//$object not used
|
||||
//$result_type not used!
|
||||
/**
|
||||
* Returns the next line in the Resultset
|
||||
*
|
||||
* @param bool $object Determines if the result will be an object or array
|
||||
* @param int $result_type Mysql Fetch result Type
|
||||
* @return array Returns an array(object) containing the next line
|
||||
*/
|
||||
public function next($object = false, $result_type = MYSQL_BOTH){
|
||||
if(\mysqli_stmt_fetch($this->res)){
|
||||
foreach( $this->binds as $key=>$value ){
|
||||
@ -54,6 +93,12 @@ class ResultMysqliPrepare extends \SYSTEM\DB\Result{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Seeks an amount of lines within the Resultset
|
||||
*
|
||||
* @param int $row_number Lines to seek over
|
||||
* @return bool Returns true or false
|
||||
*/
|
||||
public function seek($row_number){
|
||||
return \mysqli_stmt_data_seek($this->res,$row_number);}
|
||||
}
|
||||
@ -1,30 +1,70 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* System - PHP Framework
|
||||
*
|
||||
* PHP Version 5.6
|
||||
*
|
||||
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link https://github.com/webcraftmedia/system
|
||||
* @package SYSTEM\DB
|
||||
*/
|
||||
namespace SYSTEM\DB;
|
||||
|
||||
/**
|
||||
* Result Class provided by System to hold Database Query Result Ressources of PostgreSQL Querys.
|
||||
*/
|
||||
class ResultPostgres extends \SYSTEM\DB\Result{
|
||||
|
||||
/** ressource Variable to store Database Result-ressource */
|
||||
private $res = NULL;
|
||||
/** ressource Variable to store current Line either as array or object */
|
||||
private $current = NULL;
|
||||
/** ressource Variable to store Database Connection */
|
||||
private $connection = NULL;
|
||||
|
||||
//Result from mysql_query
|
||||
/**
|
||||
* Construct the Resultset with a database ressource
|
||||
*/
|
||||
public function __construct($res,$connection){
|
||||
$this->res = $res;
|
||||
$this->connection = $connection;}
|
||||
|
||||
/**
|
||||
* Close Resultset upon destruction
|
||||
*/
|
||||
public function __destruct(){
|
||||
$this->close();}
|
||||
|
||||
/**
|
||||
* Closes the Resultset
|
||||
*
|
||||
* @return null Returns null
|
||||
*/
|
||||
public function close(){
|
||||
pg_free_result($this->res);}
|
||||
|
||||
/**
|
||||
* Counts the Lines in the Resultset
|
||||
*
|
||||
* @return int Returns number of lines in the result
|
||||
*/
|
||||
public function count(){
|
||||
return pg_num_rows($this->res);}
|
||||
|
||||
/**
|
||||
* Counts the affected lines in the Resultset
|
||||
*
|
||||
* @return int Returns number of affected lines in the result
|
||||
*/
|
||||
public function affectedRows(){
|
||||
return pg_affected_rows($this->res);}
|
||||
|
||||
/**
|
||||
* Returns the next line in the Resultset
|
||||
*
|
||||
* @param bool $object Determines if the result will be an object or array
|
||||
* @return array Returns an array(object) containing the next line
|
||||
*/
|
||||
public function next($object = false){
|
||||
if($object){
|
||||
$this->current = pg_fetch_object($this->res);
|
||||
@ -34,6 +74,12 @@ class ResultPostgres extends \SYSTEM\DB\Result{
|
||||
return $this->current;
|
||||
}
|
||||
|
||||
/**
|
||||
* Seeks an amount of lines within the Resultset
|
||||
*
|
||||
* @param int $row_number Lines to seek over
|
||||
* @return bool Returns true or false
|
||||
*/
|
||||
public function seek($row_number){
|
||||
return pg_result_seek($this->res,$row_number);}
|
||||
}
|
||||
@ -1,41 +1,75 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* System - PHP Framework
|
||||
*
|
||||
* PHP Version 5.6
|
||||
*
|
||||
* @copyright 2016 Ulf Gebhardt (http://www.webcraft-media.de)
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||
* @link https://github.com/webcraftmedia/system
|
||||
* @package SYSTEM\DB
|
||||
*/
|
||||
namespace SYSTEM\DB;
|
||||
|
||||
/**
|
||||
* Result Class provided by System to hold Database Query Result Ressources of SQLite File Querys.
|
||||
*/
|
||||
class ResultSQLite extends \SYSTEM\DB\Result{
|
||||
|
||||
/** ressource Variable to store Database Result-ressource */
|
||||
private $res = NULL;
|
||||
/** ressource Variable to store query statement */
|
||||
private $stmt = NULL;
|
||||
/** ressource Variable to store current Line either as array or object */
|
||||
private $current = NULL;
|
||||
|
||||
//Result from mysql_query
|
||||
/**
|
||||
* Construct the Resultset with a database ressource
|
||||
*/
|
||||
public function __construct($res,$stmt){
|
||||
$this->res = $res;
|
||||
$this->stmt = $stmt;}
|
||||
|
||||
/**
|
||||
* Close Resultset upon destruction
|
||||
*/
|
||||
public function __destruct(){
|
||||
$this->close();}
|
||||
|
||||
/**
|
||||
* Closes the Resultset
|
||||
*
|
||||
* @return null Returns null
|
||||
*/
|
||||
public function close(){
|
||||
/*if($this->stmt){
|
||||
$this->stmt->close();}*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts the Lines in the Resultset
|
||||
*
|
||||
* @return int Returns number of lines in the result
|
||||
*/
|
||||
public function count(){
|
||||
throw new Exception("Problem SQLite");
|
||||
return mysqli_num_rows($this->res);}
|
||||
/*
|
||||
* if ($res->numColumns() && $res->columnType(0) != SQLITE3_NULL) {
|
||||
// have rows
|
||||
} else {
|
||||
// zero rows
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Counts the affected lines in the Resultset
|
||||
*
|
||||
* @return int Returns number of affected lines in the result
|
||||
*/
|
||||
public function affectedRows(){
|
||||
throw new Exception("Problem SQLite");
|
||||
return mysqli_affected_rows($this->res);}
|
||||
|
||||
/**
|
||||
* Returns the next line in the Resultset
|
||||
*
|
||||
* @param bool $object Determines if the result will be an object or array
|
||||
* @param int $result_type SQLITE Fetch result Type
|
||||
* @return array Returns an array(object) containing the next line
|
||||
*/
|
||||
public function next($object = false, $result_type = SQLITE3_ASSOC){
|
||||
if($object){
|
||||
throw new Exception("Problem SQLite");
|
||||
@ -44,37 +78,13 @@ class ResultSQLite extends \SYSTEM\DB\Result{
|
||||
}
|
||||
return $this->current;
|
||||
}
|
||||
|
||||
/*
|
||||
* function fetchObject($sqlite3result, $objectType = NULL) {
|
||||
$array = $sqlite3result->fetchArray();
|
||||
|
||||
if(is_null($objectType)) {
|
||||
$object = new stdClass();
|
||||
} else {
|
||||
// does not call this class' constructor
|
||||
$object = unserialize(sprintf('O:%d:"%s":0:{}', strlen($objectType), $objectType));
|
||||
}
|
||||
|
||||
$reflector = new ReflectionObject($object);
|
||||
for($i = 0; $i < $sqlite3result->numColumns(); $i++) {
|
||||
$name = $sqlite3result->columnName($i);
|
||||
$value = $array[$name];
|
||||
|
||||
try {
|
||||
$attribute = $reflector->getProperty($name);
|
||||
|
||||
$attribute->setAccessible(TRUE);
|
||||
$attribute->setValue($object, $value);
|
||||
} catch (ReflectionException $e) {
|
||||
$object->$name = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
/**
|
||||
* Seeks an amount of lines within the Resultset
|
||||
*
|
||||
* @param int $row_number Lines to seek over
|
||||
* @return bool Returns true or false
|
||||
*/
|
||||
|
||||
public function seek($row_number){
|
||||
throw new Exception("Problem SQLite");
|
||||
return mysqli_data_seek($this->res,$row_number);}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user