diff --git a/db/connection/Connection.php b/db/connection/Connection.php index 029f604..c903115 100644 --- a/db/connection/Connection.php +++ b/db/connection/Connection.php @@ -1,10 +1,28 @@ 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();} } \ No newline at end of file diff --git a/db/connection/ConnectionAMQP.php b/db/connection/ConnectionAMQP.php index 99d9784..0593f04 100644 --- a/db/connection/ConnectionAMQP.php +++ b/db/connection/ConnectionAMQP.php @@ -1,11 +1,28 @@ 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');} } \ No newline at end of file diff --git a/db/connection/ConnectionAbstr.php b/db/connection/ConnectionAbstr.php index 7346e43..21c1592 100644 --- a/db/connection/ConnectionAbstr.php +++ b/db/connection/ConnectionAbstr.php @@ -1,29 +1,89 @@ 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;} } \ No newline at end of file diff --git a/db/connection/ConnectionPG.php b/db/connection/ConnectionPG.php index f772c80..4bf5afb 100644 --- a/db/connection/ConnectionPG.php +++ b/db/connection/ConnectionPG.php @@ -1,23 +1,56 @@ 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');} } \ No newline at end of file diff --git a/db/connection/ConnectionSQLite.php b/db/connection/ConnectionSQLite.php index f6bcb9f..0a267ee 100644 --- a/db/connection/ConnectionSQLite.php +++ b/db/connection/ConnectionSQLite.php @@ -1,20 +1,57 @@ 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');} } \ No newline at end of file diff --git a/db/dbinfo/DBInfo.php b/db/dbinfo/DBInfo.php index 326ab1e..2d765d9 100644 --- a/db/dbinfo/DBInfo.php +++ b/db/dbinfo/DBInfo.php @@ -1,13 +1,39 @@ m_database = $vhost; $this->m_user = $user; diff --git a/db/dbinfo/DBInfoMYS.php b/db/dbinfo/DBInfoMYS.php index a7e3580..6cb0eb8 100644 --- a/db/dbinfo/DBInfoMYS.php +++ b/db/dbinfo/DBInfoMYS.php @@ -1,8 +1,29 @@ m_database = $database; $this->m_user = $user; diff --git a/db/dbinfo/DBInfoPG.php b/db/dbinfo/DBInfoPG.php index 1201904..f0e21d7 100644 --- a/db/dbinfo/DBInfoPG.php +++ b/db/dbinfo/DBInfoPG.php @@ -1,8 +1,29 @@ m_database = $database; $this->m_user = $user; diff --git a/db/dbinfo/DBInfoSQLite.php b/db/dbinfo/DBInfoSQLite.php index c89dd8e..2520c56 100644 --- a/db/dbinfo/DBInfoSQLite.php +++ b/db/dbinfo/DBInfoSQLite.php @@ -1,7 +1,29 @@ m_database = $database; $this->m_user = $user; diff --git a/db/qq/QI.php b/db/qq/QI.php index 820549a..bafd81a 100644 --- a/db/qq/QI.php +++ b/db/qq/QI.php @@ -1,6 +1,27 @@ 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);} diff --git a/db/qq/QQ.php b/db/qq/QQ.php index 6091d20..17a2e32 100644 --- a/db/qq/QQ.php +++ b/db/qq/QQ.php @@ -1,7 +1,26 @@ 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);} } \ No newline at end of file diff --git a/db/result/Result.php b/db/result/Result.php index 3eac332..2ed1710 100644 --- a/db/result/Result.php +++ b/db/result/Result.php @@ -1,16 +1,54 @@ 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);} } \ No newline at end of file diff --git a/db/result/ResultMysqli.php b/db/result/ResultMysqli.php index 92ccd74..3af222f 100644 --- a/db/result/ResultMysqli.php +++ b/db/result/ResultMysqli.php @@ -1,28 +1,68 @@ 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);} } \ No newline at end of file diff --git a/db/result/ResultMysqliPrepare.php b/db/result/ResultMysqliPrepare.php index 9ee20f6..6464751 100644 --- a/db/result/ResultMysqliPrepare.php +++ b/db/result/ResultMysqliPrepare.php @@ -1,15 +1,32 @@ 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);} } \ No newline at end of file diff --git a/db/result/ResultPostgres.php b/db/result/ResultPostgres.php index 88ae2b2..d7c8822 100644 --- a/db/result/ResultPostgres.php +++ b/db/result/ResultPostgres.php @@ -1,30 +1,70 @@ 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);} } \ No newline at end of file diff --git a/db/result/ResultSQLite.php b/db/result/ResultSQLite.php index 6c9c2d2..5bde8bb 100644 --- a/db/result/ResultSQLite.php +++ b/db/result/ResultSQLite.php @@ -1,41 +1,75 @@ 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);}