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