@@ -3,104 +3,104 @@ |
||
| 3 | 3 | jRequire("../JConfig/JConfig.php"); |
| 4 | 4 | jRequire("../Connection/Connection.php"); |
| 5 | 5 | trait Query { |
| 6 | - public $connection; |
|
| 7 | - public $currentConnection; |
|
| 8 | - public function __construct() { |
|
| 9 | - $this->connection = []; |
|
| 10 | - $this->currentConnection = null; |
|
| 11 | - } |
|
| 12 | - public function addConnection( $_path, $_name = "default" ) { |
|
| 13 | - if(!is_string($_path)) |
|
| 14 | - throw new JException("Parameter must be a string.", 1); |
|
| 15 | - try { |
|
| 16 | - $jConfig = new JConfig($_path); |
|
| 17 | - if($jConfig->enable) { |
|
| 18 | - $connection = new Connection($jConfig); |
|
| 19 | - $this->addConnectionMan($connection, $_name); |
|
| 20 | - } |
|
| 21 | - } catch (Exception $e) { |
|
| 22 | - throw new JException($e->getMessage(), 1); |
|
| 23 | - } |
|
| 24 | - } |
|
| 25 | - public function addConnectionMan( $_connection, $_name = "default") { |
|
| 26 | - if(!is_object($_connection) || !is_a($_connection, "Connection")) |
|
| 27 | - throw new JException("Parameter must be a Connection object.", 1); |
|
| 28 | - try { |
|
| 29 | - $this->connection["$_name"] = $_connection; |
|
| 30 | - $this->currentConnection = $_connection; |
|
| 31 | - foreach ($this->modules as &$module) |
|
| 32 | - if(isset($this->currentConnection)) |
|
| 33 | - $module->addConnectionMan($this->currentConnection, $_name); |
|
| 34 | - } catch (Exception $e) { |
|
| 35 | - throw new JException($e->getMessage(), 1); |
|
| 36 | - } |
|
| 37 | - } |
|
| 38 | - public function setConnection( $_name = "default" ) { |
|
| 39 | - if(!is_string($_name)) |
|
| 40 | - throw new JException("Parameter must be a string.", 1); |
|
| 41 | - if(!isset($this->connection["$_name"])) |
|
| 42 | - throw new JException("This connection name does not exist.", 1); |
|
| 43 | - $this->currentConnection = $this->connection["$_name"]; |
|
| 44 | - } |
|
| 45 | - public function query( $_query ) { |
|
| 46 | - if(!is_string($_query)) |
|
| 47 | - throw new JException("Parameter must be a string.", 1); |
|
| 48 | - if($this->currentConnection == null) |
|
| 49 | - throw new JException("No connection selected.", 1); |
|
| 50 | - try { |
|
| 51 | - $temp = $this->currentConnection->database->query($_query); |
|
| 52 | - } catch (Exception $e) { |
|
| 53 | - throw new JException($e->getMessage(), 1); |
|
| 54 | - } |
|
| 55 | - return $temp; |
|
| 56 | - } |
|
| 57 | - public function queryInsert( $_query ) { |
|
| 58 | - if(!is_string($_query)) |
|
| 59 | - throw new JException("Parameter must be a string.", 1); |
|
| 60 | - if($this->currentConnection == null) |
|
| 61 | - throw new JException("No connection selected.", 1); |
|
| 62 | - try { |
|
| 63 | - $temp = $this->currentConnection->database->queryInsert($_query); |
|
| 64 | - } catch (Exception $e) { |
|
| 65 | - throw new JException($e->getMessage(), 1); |
|
| 66 | - } |
|
| 67 | - return $temp; |
|
| 68 | - } |
|
| 69 | - public function queryFetch( $_query ) { |
|
| 70 | - if(!is_string($_query)) |
|
| 71 | - throw new JException("Parameter must be a string.", 1); |
|
| 72 | - if($this->currentConnection == null) |
|
| 73 | - throw new JException("No connection selected.", 1); |
|
| 74 | - try { |
|
| 75 | - $temp = $this->currentConnection->database->queryFetch($_query); |
|
| 76 | - } catch (Exception $e) { |
|
| 77 | - throw new JException($e->getMessage(), 1); |
|
| 78 | - } |
|
| 79 | - return $temp; |
|
| 80 | - } |
|
| 81 | - public function queryArray( $_query ) { |
|
| 82 | - if(!is_string($_query)) |
|
| 83 | - throw new JException("Parameter must be a string.", 1); |
|
| 84 | - if($this->currentConnection == null) |
|
| 85 | - throw new JException("No connection selected.", 1); |
|
| 86 | - try { |
|
| 87 | - $temp = $this->currentConnection->database->queryArray($_query); |
|
| 88 | - } catch (Exception $e) { |
|
| 89 | - throw new JException($e->getMessage(), 1); |
|
| 90 | - } |
|
| 91 | - return $temp; |
|
| 92 | - } |
|
| 93 | - public function newTable( $_query ) { |
|
| 94 | - if(!is_string($_query)) |
|
| 95 | - throw new JException("Parameter must be a string.", 1); |
|
| 96 | - if($this->currentConnection == null) |
|
| 97 | - throw new JException("No connection selected.", 1); |
|
| 98 | - try { |
|
| 99 | - $temp = $this->currentConnection->database->newTable($_query); |
|
| 100 | - } catch (Exception $e) { |
|
| 101 | - throw new JException($e->getMessage(), 1); |
|
| 102 | - } |
|
| 103 | - return $temp; |
|
| 104 | - } |
|
| 6 | + public $connection; |
|
| 7 | + public $currentConnection; |
|
| 8 | + public function __construct() { |
|
| 9 | + $this->connection = []; |
|
| 10 | + $this->currentConnection = null; |
|
| 11 | + } |
|
| 12 | + public function addConnection( $_path, $_name = "default" ) { |
|
| 13 | + if(!is_string($_path)) |
|
| 14 | + throw new JException("Parameter must be a string.", 1); |
|
| 15 | + try { |
|
| 16 | + $jConfig = new JConfig($_path); |
|
| 17 | + if($jConfig->enable) { |
|
| 18 | + $connection = new Connection($jConfig); |
|
| 19 | + $this->addConnectionMan($connection, $_name); |
|
| 20 | + } |
|
| 21 | + } catch (Exception $e) { |
|
| 22 | + throw new JException($e->getMessage(), 1); |
|
| 23 | + } |
|
| 24 | + } |
|
| 25 | + public function addConnectionMan( $_connection, $_name = "default") { |
|
| 26 | + if(!is_object($_connection) || !is_a($_connection, "Connection")) |
|
| 27 | + throw new JException("Parameter must be a Connection object.", 1); |
|
| 28 | + try { |
|
| 29 | + $this->connection["$_name"] = $_connection; |
|
| 30 | + $this->currentConnection = $_connection; |
|
| 31 | + foreach ($this->modules as &$module) |
|
| 32 | + if(isset($this->currentConnection)) |
|
| 33 | + $module->addConnectionMan($this->currentConnection, $_name); |
|
| 34 | + } catch (Exception $e) { |
|
| 35 | + throw new JException($e->getMessage(), 1); |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | + public function setConnection( $_name = "default" ) { |
|
| 39 | + if(!is_string($_name)) |
|
| 40 | + throw new JException("Parameter must be a string.", 1); |
|
| 41 | + if(!isset($this->connection["$_name"])) |
|
| 42 | + throw new JException("This connection name does not exist.", 1); |
|
| 43 | + $this->currentConnection = $this->connection["$_name"]; |
|
| 44 | + } |
|
| 45 | + public function query( $_query ) { |
|
| 46 | + if(!is_string($_query)) |
|
| 47 | + throw new JException("Parameter must be a string.", 1); |
|
| 48 | + if($this->currentConnection == null) |
|
| 49 | + throw new JException("No connection selected.", 1); |
|
| 50 | + try { |
|
| 51 | + $temp = $this->currentConnection->database->query($_query); |
|
| 52 | + } catch (Exception $e) { |
|
| 53 | + throw new JException($e->getMessage(), 1); |
|
| 54 | + } |
|
| 55 | + return $temp; |
|
| 56 | + } |
|
| 57 | + public function queryInsert( $_query ) { |
|
| 58 | + if(!is_string($_query)) |
|
| 59 | + throw new JException("Parameter must be a string.", 1); |
|
| 60 | + if($this->currentConnection == null) |
|
| 61 | + throw new JException("No connection selected.", 1); |
|
| 62 | + try { |
|
| 63 | + $temp = $this->currentConnection->database->queryInsert($_query); |
|
| 64 | + } catch (Exception $e) { |
|
| 65 | + throw new JException($e->getMessage(), 1); |
|
| 66 | + } |
|
| 67 | + return $temp; |
|
| 68 | + } |
|
| 69 | + public function queryFetch( $_query ) { |
|
| 70 | + if(!is_string($_query)) |
|
| 71 | + throw new JException("Parameter must be a string.", 1); |
|
| 72 | + if($this->currentConnection == null) |
|
| 73 | + throw new JException("No connection selected.", 1); |
|
| 74 | + try { |
|
| 75 | + $temp = $this->currentConnection->database->queryFetch($_query); |
|
| 76 | + } catch (Exception $e) { |
|
| 77 | + throw new JException($e->getMessage(), 1); |
|
| 78 | + } |
|
| 79 | + return $temp; |
|
| 80 | + } |
|
| 81 | + public function queryArray( $_query ) { |
|
| 82 | + if(!is_string($_query)) |
|
| 83 | + throw new JException("Parameter must be a string.", 1); |
|
| 84 | + if($this->currentConnection == null) |
|
| 85 | + throw new JException("No connection selected.", 1); |
|
| 86 | + try { |
|
| 87 | + $temp = $this->currentConnection->database->queryArray($_query); |
|
| 88 | + } catch (Exception $e) { |
|
| 89 | + throw new JException($e->getMessage(), 1); |
|
| 90 | + } |
|
| 91 | + return $temp; |
|
| 92 | + } |
|
| 93 | + public function newTable( $_query ) { |
|
| 94 | + if(!is_string($_query)) |
|
| 95 | + throw new JException("Parameter must be a string.", 1); |
|
| 96 | + if($this->currentConnection == null) |
|
| 97 | + throw new JException("No connection selected.", 1); |
|
| 98 | + try { |
|
| 99 | + $temp = $this->currentConnection->database->newTable($_query); |
|
| 100 | + } catch (Exception $e) { |
|
| 101 | + throw new JException($e->getMessage(), 1); |
|
| 102 | + } |
|
| 103 | + return $temp; |
|
| 104 | + } |
|
| 105 | 105 | } |
| 106 | 106 | ?> |