@@ -9,12 +9,12 @@ discard block |
||
9 | 9 | $this->connection = []; |
10 | 10 | $this->currentConnection = null; |
11 | 11 | } |
12 | - public function addConnection( $_path, $_name = "default" ) { |
|
13 | - if(!is_string($_path)) |
|
12 | + public function addConnection($_path, $_name = "default") { |
|
13 | + if (!is_string($_path)) |
|
14 | 14 | throw new JException("Parameter must be a string.", 1); |
15 | 15 | try { |
16 | 16 | $jConfig = new JConfig($_path); |
17 | - if($jConfig->enable) { |
|
17 | + if ($jConfig->enable) { |
|
18 | 18 | $connection = new Connection($jConfig); |
19 | 19 | $this->addConnectionMan($connection, $_name); |
20 | 20 | } |
@@ -22,28 +22,28 @@ discard block |
||
22 | 22 | throw new JException($e->getMessage(), 1); |
23 | 23 | } |
24 | 24 | } |
25 | - public function addConnectionMan( $_connection, $_name = "default") { |
|
26 | - if(!is_object($_connection) || !is_a($_connection, "Connection")) |
|
25 | + public function addConnectionMan($_connection, $_name = "default") { |
|
26 | + if (!is_object($_connection) || !is_a($_connection, "Connection")) |
|
27 | 27 | throw new JException("Parameter must be a Connection object.", 1); |
28 | 28 | try { |
29 | 29 | $this->connection["$_name"] = $_connection; |
30 | 30 | $this->currentConnection = $_connection; |
31 | 31 | foreach ($this->modules as &$module) |
32 | - if(isset($this->currentConnection)) |
|
32 | + if (isset($this->currentConnection)) |
|
33 | 33 | $module->addConnectionMan($this->currentConnection, $_name); |
34 | 34 | } catch (Exception $e) { |
35 | 35 | throw new JException($e->getMessage(), 1); |
36 | 36 | } |
37 | 37 | } |
38 | - public function setConnection( $_name = "default" ) { |
|
39 | - if(!is_string($_name)) |
|
38 | + public function setConnection($_name = "default") { |
|
39 | + if (!is_string($_name)) |
|
40 | 40 | throw new JException("Parameter must be a string.", 1); |
41 | - if(!isset($this->connection["$_name"])) |
|
41 | + if (!isset($this->connection["$_name"])) |
|
42 | 42 | throw new JException("This connection name does not exist.", 1); |
43 | 43 | $this->currentConnection = $this->connection["$_name"]; |
44 | 44 | } |
45 | - public function query( $_query ) { |
|
46 | - if(!is_string($_query)) |
|
45 | + public function query($_query) { |
|
46 | + if (!is_string($_query)) |
|
47 | 47 | throw new JException("Parameter must be a string.", 1); |
48 | 48 | try { |
49 | 49 | $temp = $this->currentConnection->database->query($_query); |
@@ -52,8 +52,8 @@ discard block |
||
52 | 52 | } |
53 | 53 | return $temp; |
54 | 54 | } |
55 | - public function queryInsert( $_query ) { |
|
56 | - if(!is_string($_query)) |
|
55 | + public function queryInsert($_query) { |
|
56 | + if (!is_string($_query)) |
|
57 | 57 | throw new JException("Parameter must be a string.", 1); |
58 | 58 | try { |
59 | 59 | $temp = $this->currentConnection->database->queryInsert($_query); |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | } |
63 | 63 | return $temp; |
64 | 64 | } |
65 | - public function queryFetch( $_query ) { |
|
66 | - if(!is_string($_query)) |
|
65 | + public function queryFetch($_query) { |
|
66 | + if (!is_string($_query)) |
|
67 | 67 | throw new JException("Parameter must be a string.", 1); |
68 | 68 | try { |
69 | 69 | $temp = $this->currentConnection->database->queryFetch($_query); |
@@ -72,8 +72,8 @@ discard block |
||
72 | 72 | } |
73 | 73 | return $temp; |
74 | 74 | } |
75 | - public function queryArray( $_query ) { |
|
76 | - if(!is_string($_query)) |
|
75 | + public function queryArray($_query) { |
|
76 | + if (!is_string($_query)) |
|
77 | 77 | throw new JException("Parameter must be a string.", 1); |
78 | 78 | try { |
79 | 79 | $temp = $this->currentConnection->database->queryArray($_query); |
@@ -82,8 +82,8 @@ discard block |
||
82 | 82 | } |
83 | 83 | return $temp; |
84 | 84 | } |
85 | - public function newTable( $_query ) { |
|
86 | - if(!is_string($_query)) |
|
85 | + public function newTable($_query) { |
|
86 | + if (!is_string($_query)) |
|
87 | 87 | throw new JException("Parameter must be a string.", 1); |
88 | 88 | try { |
89 | 89 | $temp = $this->currentConnection->database->newTable($_query); |
@@ -3,8 +3,8 @@ discard block |
||
3 | 3 | class Connection { |
4 | 4 | public $database; |
5 | 5 | public $info; |
6 | - public function __construct( $_object ) { |
|
7 | - if(!is_object($_object)) |
|
6 | + public function __construct($_object) { |
|
7 | + if (!is_object($_object)) |
|
8 | 8 | throw new JException("Parameter must be an object."); |
9 | 9 | $this->setConnection( |
10 | 10 | $_object->server, |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | $this->getConnectionType($_object->engine) |
15 | 15 | ); |
16 | 16 | } |
17 | - protected function setConnection ( $_srv, $_db, $_usr, $_pass, $_type ) { |
|
17 | + protected function setConnection($_srv, $_db, $_usr, $_pass, $_type) { |
|
18 | 18 | switch ($_type) { |
19 | 19 | case "mysqli": |
20 | 20 | $this->database = new MysqliAdapter($_srv, $_db, $_usr, $_pass); |
@@ -38,10 +38,10 @@ discard block |
||
38 | 38 | "type" => $_type |
39 | 39 | ]; |
40 | 40 | } |
41 | - protected function getConnectionType( $_type ) { |
|
42 | - $array = (array)$_type; |
|
41 | + protected function getConnectionType($_type) { |
|
42 | + $array = (array) $_type; |
|
43 | 43 | foreach ($array as $key => $value) |
44 | - if($value) |
|
44 | + if ($value) |
|
45 | 45 | return $key; |
46 | 46 | return "pdo"; |
47 | 47 | } |
@@ -2,14 +2,14 @@ |
||
2 | 2 | jRequire("PdoAdapterMysql.php"); |
3 | 3 | class PdoAdapterSqLiteMemory extends PdoAdapterMysql { |
4 | 4 | public $connection; |
5 | - public function __construct( $_srv, $_db, $_usr, $_pass ) { |
|
5 | + public function __construct($_srv, $_db, $_usr, $_pass) { |
|
6 | 6 | try { |
7 | 7 | $this->connection = new PDO("sqlite::memory:"); |
8 | - } catch( Exception $e ) { |
|
8 | + } catch (Exception $e) { |
|
9 | 9 | throw new JException($e->getMessage()); |
10 | 10 | } |
11 | 11 | } |
12 | - public function newTable( $_sql ) { |
|
12 | + public function newTable($_sql) { |
|
13 | 13 | try { |
14 | 14 | $temp = $this->connection->exec($_sql); |
15 | 15 | } catch (Exception $e) { |
@@ -2,35 +2,35 @@ |
||
2 | 2 | jRequire("ConnectionInterface.php"); |
3 | 3 | class PdoAdapterMysql implements ConnectionAdapterInterface { |
4 | 4 | public $connection; |
5 | - public function __construct( $_srv, $_db, $_usr, $_pass ) { |
|
5 | + public function __construct($_srv, $_db, $_usr, $_pass) { |
|
6 | 6 | try { |
7 | 7 | $connection = "mysql:host=$_srv;dbname=$_db"; |
8 | - $this->connection = new PDO( $connection, $_usr, $_pass, [PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'"] ); |
|
9 | - } catch( Exception $e ) { |
|
8 | + $this->connection = new PDO($connection, $_usr, $_pass, [PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'"]); |
|
9 | + } catch (Exception $e) { |
|
10 | 10 | throw new JException($e->getMessage()); |
11 | 11 | } |
12 | 12 | } |
13 | - public function query( $_query ) { |
|
13 | + public function query($_query) { |
|
14 | 14 | $this->stdQuery($_query); |
15 | 15 | return true; |
16 | 16 | } |
17 | - public function queryInsert( $_query ) { |
|
17 | + public function queryInsert($_query) { |
|
18 | 18 | $this->stdQuery($_query); |
19 | 19 | return $this->connection->lastInsertId(); |
20 | 20 | } |
21 | - public function queryFetch( $_query ) { |
|
21 | + public function queryFetch($_query) { |
|
22 | 22 | $temp = $this->stdQuery($_query); |
23 | 23 | return $temp->fetchAll(PDO::FETCH_ASSOC); |
24 | 24 | } |
25 | - public function queryArray( $_query ) { |
|
25 | + public function queryArray($_query) { |
|
26 | 26 | $temp = $this->stdQuery($_query); |
27 | 27 | return $temp->fetchAll(PDO::FETCH_COLUMN, 0); |
28 | 28 | } |
29 | - protected function stdQuery( $_query ) { |
|
29 | + protected function stdQuery($_query) { |
|
30 | 30 | $database = $this->connection; |
31 | 31 | $query = $database->prepare($_query); |
32 | 32 | $result = $query->execute(); |
33 | - if(!$result) |
|
33 | + if (!$result) |
|
34 | 34 | throw new JException(json_encode([ |
35 | 35 | "query" => $_query, |
36 | 36 | "error" => [ |