@@ -2,51 +2,51 @@ |
||
2 | 2 | jRequire("../Module/Module.php"); |
3 | 3 | requireComponents("Adapters"); |
4 | 4 | class Connection extends Module { |
5 | - public $database; |
|
6 | - public $info; |
|
7 | - public function __construct() { |
|
8 | - parent::__construct(); |
|
9 | - $args = func_get_args(); |
|
10 | - $count = func_num_args(); |
|
11 | - if (method_exists($this,$func='__construct'.$count)) |
|
12 | - call_user_func_array(array($this,$func),$args); |
|
13 | - } |
|
14 | - public function __construct0() { |
|
15 | - $this->database = null; |
|
16 | - } |
|
17 | - public function __construct4 ( $_srv, $_db, $_usr, $_pass ) { |
|
18 | - $this->setConnection($_srv, $_db, $_usr, $_pass, "pdo"); |
|
19 | - } |
|
20 | - public function __construct5 ( $_srv, $_db, $_usr, $_pass, $_type ) { |
|
21 | - $type = $this->getConnectionType($_type); |
|
22 | - $this->setConnection($_srv, $_db, $_usr, $_pass, $type); |
|
23 | - } |
|
24 | - protected function setConnection ( $_srv, $_db, $_usr, $_pass, $_type ) { |
|
25 | - switch ($_type) { |
|
26 | - case "mysqli": |
|
27 | - $this->database = new ConnectionMysqliAdapter($_srv, $_db, $_usr, $_pass); |
|
28 | - break; |
|
29 | - case "postgresql": |
|
30 | - $this->database = new ConnectionPostgresqlAdapter($_srv, $_db, $_usr, $_pass); |
|
31 | - break; |
|
32 | - default: |
|
33 | - $this->database = new ConnectionPdoAdapter($_srv, $_db, $_usr, $_pass); |
|
34 | - break; |
|
35 | - } |
|
36 | - $this->setConnectionParameters( $_srv, $_db, $_usr, $_pass); |
|
37 | - } |
|
38 | - protected function getConnectionType( $_type ) { |
|
39 | - foreach ($_type as $key => $value) |
|
40 | - if($value) |
|
41 | - return $key; |
|
42 | - return "pdo"; |
|
43 | - } |
|
44 | - protected function setConnectionParameters( $_srv, $_db, $_usr, $_pass) { |
|
45 | - $this->info = []; |
|
46 | - $this->info["server"] = $_srv; |
|
47 | - $this->info["database"] = $_db; |
|
48 | - $this->info["user"] = $_usr; |
|
49 | - $this->info["password"] = $_pass; |
|
50 | - } |
|
5 | + public $database; |
|
6 | + public $info; |
|
7 | + public function __construct() { |
|
8 | + parent::__construct(); |
|
9 | + $args = func_get_args(); |
|
10 | + $count = func_num_args(); |
|
11 | + if (method_exists($this,$func='__construct'.$count)) |
|
12 | + call_user_func_array(array($this,$func),$args); |
|
13 | + } |
|
14 | + public function __construct0() { |
|
15 | + $this->database = null; |
|
16 | + } |
|
17 | + public function __construct4 ( $_srv, $_db, $_usr, $_pass ) { |
|
18 | + $this->setConnection($_srv, $_db, $_usr, $_pass, "pdo"); |
|
19 | + } |
|
20 | + public function __construct5 ( $_srv, $_db, $_usr, $_pass, $_type ) { |
|
21 | + $type = $this->getConnectionType($_type); |
|
22 | + $this->setConnection($_srv, $_db, $_usr, $_pass, $type); |
|
23 | + } |
|
24 | + protected function setConnection ( $_srv, $_db, $_usr, $_pass, $_type ) { |
|
25 | + switch ($_type) { |
|
26 | + case "mysqli": |
|
27 | + $this->database = new ConnectionMysqliAdapter($_srv, $_db, $_usr, $_pass); |
|
28 | + break; |
|
29 | + case "postgresql": |
|
30 | + $this->database = new ConnectionPostgresqlAdapter($_srv, $_db, $_usr, $_pass); |
|
31 | + break; |
|
32 | + default: |
|
33 | + $this->database = new ConnectionPdoAdapter($_srv, $_db, $_usr, $_pass); |
|
34 | + break; |
|
35 | + } |
|
36 | + $this->setConnectionParameters( $_srv, $_db, $_usr, $_pass); |
|
37 | + } |
|
38 | + protected function getConnectionType( $_type ) { |
|
39 | + foreach ($_type as $key => $value) |
|
40 | + if($value) |
|
41 | + return $key; |
|
42 | + return "pdo"; |
|
43 | + } |
|
44 | + protected function setConnectionParameters( $_srv, $_db, $_usr, $_pass) { |
|
45 | + $this->info = []; |
|
46 | + $this->info["server"] = $_srv; |
|
47 | + $this->info["database"] = $_db; |
|
48 | + $this->info["user"] = $_usr; |
|
49 | + $this->info["password"] = $_pass; |
|
50 | + } |
|
51 | 51 | } |
52 | 52 | ?> |
@@ -1,55 +1,55 @@ |
||
1 | 1 | <?php |
2 | 2 | class JConfig { |
3 | - public $connection; |
|
4 | - public $all; |
|
5 | - public $DEBUG; |
|
6 | - public $pages; |
|
7 | - public $server; |
|
8 | - public function __construct() { |
|
9 | - $this->connection["enable"] = false; |
|
10 | - $this->connection["user"] = ""; |
|
11 | - $this->connection["password"] = ""; |
|
12 | - $this->connection["database"] = ""; |
|
13 | - $this->connection["server"] = ""; |
|
14 | - $this->all = ""; |
|
15 | - $this->DEBUG = 0; |
|
16 | - $this->pages = []; |
|
17 | - $this->server = []; |
|
18 | - $this->server["HTTP_HOST"] = $_SERVER["HTTP_HOST"]; |
|
19 | - $this->server["REQUEST_URI"] = $_SERVER["REQUEST_URI"]; |
|
20 | - $this->server["PHP_SELF"] = $_SERVER["PHP_SELF"]; |
|
21 | - $this->server["RELATIVE"] = str_replace("/index.php", "", $_SERVER["PHP_SELF"]); |
|
22 | - } |
|
23 | - public function import( $_path, $_type = "misc" ) { |
|
24 | - $data = file_get_contents($_path); |
|
25 | - $data = json_decode($data); |
|
26 | - if($data === NULL) |
|
27 | - Debug::log("Error processing [$_path]"); |
|
28 | - if( $_type == "connection" ) |
|
29 | - $this->overlayConnection($data); |
|
30 | - else |
|
31 | - $this->overlayMisc($data); |
|
32 | - } |
|
33 | - protected function overlayConnection( $_data ) { |
|
34 | - $this->connection = $this->obj2array($_data); |
|
35 | - } |
|
36 | - protected function overlayMisc( $_data ) { |
|
37 | - $this->importObject($_data); |
|
38 | - } |
|
39 | - protected function obj2array ( &$_instance ) { |
|
40 | - $clone = (array) $_instance; |
|
41 | - $return = []; |
|
42 | - $return['___SOURCE_KEYS_'] = $clone; |
|
43 | - while ( list ($key, $value) = each ($clone) ) { |
|
44 | - $temp = explode ("\0", $key); |
|
45 | - $newkey = $temp[count($temp)-1]; |
|
46 | - $return[$newkey] = &$return['___SOURCE_KEYS_'][$key]; |
|
47 | - } |
|
48 | - return $return; |
|
49 | - } |
|
50 | - protected function importObject( $_object ) { |
|
51 | - foreach (get_object_vars($_object) as $key => $value) |
|
52 | - $this->$key = $value; |
|
53 | - } |
|
3 | + public $connection; |
|
4 | + public $all; |
|
5 | + public $DEBUG; |
|
6 | + public $pages; |
|
7 | + public $server; |
|
8 | + public function __construct() { |
|
9 | + $this->connection["enable"] = false; |
|
10 | + $this->connection["user"] = ""; |
|
11 | + $this->connection["password"] = ""; |
|
12 | + $this->connection["database"] = ""; |
|
13 | + $this->connection["server"] = ""; |
|
14 | + $this->all = ""; |
|
15 | + $this->DEBUG = 0; |
|
16 | + $this->pages = []; |
|
17 | + $this->server = []; |
|
18 | + $this->server["HTTP_HOST"] = $_SERVER["HTTP_HOST"]; |
|
19 | + $this->server["REQUEST_URI"] = $_SERVER["REQUEST_URI"]; |
|
20 | + $this->server["PHP_SELF"] = $_SERVER["PHP_SELF"]; |
|
21 | + $this->server["RELATIVE"] = str_replace("/index.php", "", $_SERVER["PHP_SELF"]); |
|
22 | + } |
|
23 | + public function import( $_path, $_type = "misc" ) { |
|
24 | + $data = file_get_contents($_path); |
|
25 | + $data = json_decode($data); |
|
26 | + if($data === NULL) |
|
27 | + Debug::log("Error processing [$_path]"); |
|
28 | + if( $_type == "connection" ) |
|
29 | + $this->overlayConnection($data); |
|
30 | + else |
|
31 | + $this->overlayMisc($data); |
|
32 | + } |
|
33 | + protected function overlayConnection( $_data ) { |
|
34 | + $this->connection = $this->obj2array($_data); |
|
35 | + } |
|
36 | + protected function overlayMisc( $_data ) { |
|
37 | + $this->importObject($_data); |
|
38 | + } |
|
39 | + protected function obj2array ( &$_instance ) { |
|
40 | + $clone = (array) $_instance; |
|
41 | + $return = []; |
|
42 | + $return['___SOURCE_KEYS_'] = $clone; |
|
43 | + while ( list ($key, $value) = each ($clone) ) { |
|
44 | + $temp = explode ("\0", $key); |
|
45 | + $newkey = $temp[count($temp)-1]; |
|
46 | + $return[$newkey] = &$return['___SOURCE_KEYS_'][$key]; |
|
47 | + } |
|
48 | + return $return; |
|
49 | + } |
|
50 | + protected function importObject( $_object ) { |
|
51 | + foreach (get_object_vars($_object) as $key => $value) |
|
52 | + $this->$key = $value; |
|
53 | + } |
|
54 | 54 | } |
55 | 55 | ?> |
@@ -1,48 +1,48 @@ |
||
1 | 1 | <?php |
2 | 2 | jRequire("../Module/Module.php"); |
3 | 3 | class Query extends Module { |
4 | - public $connection; |
|
5 | - public $currentConnection; |
|
6 | - public function __construct() { |
|
7 | - parent::__construct(); |
|
8 | - $this->connection = []; |
|
9 | - $this->currentConnection = null; |
|
10 | - } |
|
11 | - public function addConnection( $_name, $_connection ) { |
|
12 | - Debug::push(); |
|
13 | - $this->connection["$_name"] = $_connection; |
|
14 | - $this->currentConnection = $_connection; |
|
15 | - foreach ($this->modules as &$module) |
|
16 | - if(isset($module->currentConnection)) |
|
17 | - $module->addConnection($_name, $_connection); |
|
18 | - Debug::pop(); |
|
19 | - } |
|
20 | - public function setConnection( $_name ) { |
|
21 | - $this->currentConnection = $this->connection["$_name"]; |
|
22 | - } |
|
23 | - public function query( $_query ) { |
|
24 | - Debug::push(); |
|
25 | - $temp = $this->currentConnection->database->query($_query); |
|
26 | - Debug::pop(); |
|
27 | - return $temp; |
|
28 | - } |
|
29 | - public function queryInsert( $_query ) { |
|
30 | - Debug::push(); |
|
31 | - $temp = $this->currentConnection->database->queryInsert($_query); |
|
32 | - Debug::pop(); |
|
33 | - return $temp; |
|
34 | - } |
|
35 | - public function queryFetch( $_query ) { |
|
36 | - Debug::push(); |
|
37 | - $temp = $this->currentConnection->database->queryFetch($_query); |
|
38 | - Debug::pop(); |
|
39 | - return $temp; |
|
40 | - } |
|
41 | - public function queryArray( $_query ) { |
|
42 | - Debug::push(); |
|
43 | - $temp = $this->currentConnection->database->queryArray($_query); |
|
44 | - Debug::pop(); |
|
45 | - return $temp; |
|
46 | - } |
|
4 | + public $connection; |
|
5 | + public $currentConnection; |
|
6 | + public function __construct() { |
|
7 | + parent::__construct(); |
|
8 | + $this->connection = []; |
|
9 | + $this->currentConnection = null; |
|
10 | + } |
|
11 | + public function addConnection( $_name, $_connection ) { |
|
12 | + Debug::push(); |
|
13 | + $this->connection["$_name"] = $_connection; |
|
14 | + $this->currentConnection = $_connection; |
|
15 | + foreach ($this->modules as &$module) |
|
16 | + if(isset($module->currentConnection)) |
|
17 | + $module->addConnection($_name, $_connection); |
|
18 | + Debug::pop(); |
|
19 | + } |
|
20 | + public function setConnection( $_name ) { |
|
21 | + $this->currentConnection = $this->connection["$_name"]; |
|
22 | + } |
|
23 | + public function query( $_query ) { |
|
24 | + Debug::push(); |
|
25 | + $temp = $this->currentConnection->database->query($_query); |
|
26 | + Debug::pop(); |
|
27 | + return $temp; |
|
28 | + } |
|
29 | + public function queryInsert( $_query ) { |
|
30 | + Debug::push(); |
|
31 | + $temp = $this->currentConnection->database->queryInsert($_query); |
|
32 | + Debug::pop(); |
|
33 | + return $temp; |
|
34 | + } |
|
35 | + public function queryFetch( $_query ) { |
|
36 | + Debug::push(); |
|
37 | + $temp = $this->currentConnection->database->queryFetch($_query); |
|
38 | + Debug::pop(); |
|
39 | + return $temp; |
|
40 | + } |
|
41 | + public function queryArray( $_query ) { |
|
42 | + Debug::push(); |
|
43 | + $temp = $this->currentConnection->database->queryArray($_query); |
|
44 | + Debug::pop(); |
|
45 | + return $temp; |
|
46 | + } |
|
47 | 47 | } |
48 | 48 | ?> |
@@ -1,47 +1,47 @@ |
||
1 | 1 | <?php |
2 | 2 | jRequire("ConnectionInterface.php"); |
3 | 3 | class ConnectionPdoAdapter 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 $error ) { |
|
10 | - Debug::log($error->getMessage()); |
|
11 | - exit(); |
|
12 | - } |
|
13 | - } |
|
14 | - public function query( $_query ) { |
|
15 | - $this->stdQuery($_query); |
|
16 | - return true; |
|
17 | - } |
|
18 | - public function queryInsert( $_query ) { |
|
19 | - $this->stdQuery($_query); |
|
20 | - return $this->connection->lastInsertId(); |
|
21 | - } |
|
22 | - public function queryFetch( $_query ) { |
|
23 | - $temp = $this->stdQuery($_query); |
|
24 | - return $temp->fetchAll(PDO::FETCH_ASSOC); |
|
25 | - } |
|
26 | - public function queryArray( $_query ) { |
|
27 | - $temp = $this->stdQuery($_query); |
|
28 | - return $temp->fetchAll(PDO::FETCH_COLUMN, 0); |
|
29 | - } |
|
30 | - protected function stdQuery( $_query ) { |
|
31 | - $database = $this->connection; |
|
32 | - $query = $database->prepare($_query); |
|
33 | - $result = $query->execute(); |
|
34 | - if(!$result) { |
|
35 | - Debug::logStack([ |
|
36 | - "query" => $_query, |
|
37 | - "error" => [ |
|
38 | - $query->errorInfo(), |
|
39 | - $database->errorInfo() |
|
40 | - ] |
|
41 | - ]); |
|
42 | - exit(); |
|
43 | - } |
|
44 | - return $query; |
|
45 | - } |
|
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 $error ) { |
|
10 | + Debug::log($error->getMessage()); |
|
11 | + exit(); |
|
12 | + } |
|
13 | + } |
|
14 | + public function query( $_query ) { |
|
15 | + $this->stdQuery($_query); |
|
16 | + return true; |
|
17 | + } |
|
18 | + public function queryInsert( $_query ) { |
|
19 | + $this->stdQuery($_query); |
|
20 | + return $this->connection->lastInsertId(); |
|
21 | + } |
|
22 | + public function queryFetch( $_query ) { |
|
23 | + $temp = $this->stdQuery($_query); |
|
24 | + return $temp->fetchAll(PDO::FETCH_ASSOC); |
|
25 | + } |
|
26 | + public function queryArray( $_query ) { |
|
27 | + $temp = $this->stdQuery($_query); |
|
28 | + return $temp->fetchAll(PDO::FETCH_COLUMN, 0); |
|
29 | + } |
|
30 | + protected function stdQuery( $_query ) { |
|
31 | + $database = $this->connection; |
|
32 | + $query = $database->prepare($_query); |
|
33 | + $result = $query->execute(); |
|
34 | + if(!$result) { |
|
35 | + Debug::logStack([ |
|
36 | + "query" => $_query, |
|
37 | + "error" => [ |
|
38 | + $query->errorInfo(), |
|
39 | + $database->errorInfo() |
|
40 | + ] |
|
41 | + ]); |
|
42 | + exit(); |
|
43 | + } |
|
44 | + return $query; |
|
45 | + } |
|
46 | 46 | } |
47 | 47 | ?> |
@@ -1,51 +1,51 @@ |
||
1 | 1 | <?php |
2 | 2 | jRequire("ConnectionInterface.php"); |
3 | 3 | class ConnectionPostgresqlAdapter implements ConnectionAdapterInterface { |
4 | - public $connection; |
|
5 | - public function __construct( $_srv, $_db, $_usr, $_pass ) { |
|
6 | - try { |
|
7 | - $this->connection = pg_connect("host=$_srv dbname=$_db user=$_usr password=$_pass") |
|
8 | - or die('Could not connect: '.pg_last_error()); |
|
9 | - } catch( Exception $error ) { |
|
10 | - Debug::log($error->getMessage()); |
|
11 | - exit(); |
|
12 | - } |
|
13 | - } |
|
14 | - public function query( $_query ) { |
|
15 | - $this->stdQuery($_query); |
|
16 | - return true; |
|
17 | - } |
|
18 | - public function queryInsert( $_query ) { |
|
19 | - $this->stdQuery($_query); |
|
20 | - return $this->stdQuery("SELECT lastval()"); |
|
21 | - } |
|
22 | - public function queryFetch( $_query ) { |
|
23 | - $result = $this->stdQuery($_query); |
|
24 | - $rows = []; |
|
25 | - while($row = pg_fetch_assoc($result)) |
|
26 | - $rows[] = $row; |
|
27 | - pg_free_result($result); |
|
28 | - return $rows; |
|
29 | - } |
|
30 | - public function queryArray( $_query ) { |
|
31 | - $result = $this->stdQuery($_query); |
|
32 | - $rows = []; |
|
33 | - while($row = pg_fetch_array($result)) |
|
34 | - $rows[] = $row; |
|
35 | - pg_free_result($result); |
|
36 | - return $rows; |
|
37 | - } |
|
38 | - protected function stdQuery( $_query ) { |
|
39 | - $database = $this->connection; |
|
40 | - $result = pg_query($database, $_query); |
|
41 | - if(!$result) { |
|
42 | - Debug::logStack([ |
|
43 | - "query" => $_query, |
|
44 | - "error" => pg_last_error() |
|
45 | - ]); |
|
46 | - exit(); |
|
47 | - } |
|
48 | - return $result; |
|
49 | - } |
|
4 | + public $connection; |
|
5 | + public function __construct( $_srv, $_db, $_usr, $_pass ) { |
|
6 | + try { |
|
7 | + $this->connection = pg_connect("host=$_srv dbname=$_db user=$_usr password=$_pass") |
|
8 | + or die('Could not connect: '.pg_last_error()); |
|
9 | + } catch( Exception $error ) { |
|
10 | + Debug::log($error->getMessage()); |
|
11 | + exit(); |
|
12 | + } |
|
13 | + } |
|
14 | + public function query( $_query ) { |
|
15 | + $this->stdQuery($_query); |
|
16 | + return true; |
|
17 | + } |
|
18 | + public function queryInsert( $_query ) { |
|
19 | + $this->stdQuery($_query); |
|
20 | + return $this->stdQuery("SELECT lastval()"); |
|
21 | + } |
|
22 | + public function queryFetch( $_query ) { |
|
23 | + $result = $this->stdQuery($_query); |
|
24 | + $rows = []; |
|
25 | + while($row = pg_fetch_assoc($result)) |
|
26 | + $rows[] = $row; |
|
27 | + pg_free_result($result); |
|
28 | + return $rows; |
|
29 | + } |
|
30 | + public function queryArray( $_query ) { |
|
31 | + $result = $this->stdQuery($_query); |
|
32 | + $rows = []; |
|
33 | + while($row = pg_fetch_array($result)) |
|
34 | + $rows[] = $row; |
|
35 | + pg_free_result($result); |
|
36 | + return $rows; |
|
37 | + } |
|
38 | + protected function stdQuery( $_query ) { |
|
39 | + $database = $this->connection; |
|
40 | + $result = pg_query($database, $_query); |
|
41 | + if(!$result) { |
|
42 | + Debug::logStack([ |
|
43 | + "query" => $_query, |
|
44 | + "error" => pg_last_error() |
|
45 | + ]); |
|
46 | + exit(); |
|
47 | + } |
|
48 | + return $result; |
|
49 | + } |
|
50 | 50 | } |
51 | 51 | ?> |
@@ -1,48 +1,48 @@ |
||
1 | 1 | <?php |
2 | 2 | jRequire("ConnectionInterface.php"); |
3 | 3 | class ConnectionMysqliAdapter implements ConnectionAdapterInterface { |
4 | - public $connection; |
|
5 | - public function __construct( $_srv, $_db, $_usr, $_pass ) { |
|
6 | - try { |
|
7 | - $this->connection = new mysqli( $_srv, $_usr, $_pass, $_db ); |
|
8 | - } catch( Exception $error ) { |
|
9 | - Debug::log($error->getMessage()); |
|
10 | - exit(); |
|
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->insert_id; |
|
20 | - } |
|
21 | - public function queryFetch( $_query ) { |
|
22 | - $result = $this->stdQuery($_query); |
|
23 | - $rows = []; |
|
24 | - while($row = $result->fetch_assoc()) |
|
25 | - $rows[] = $row; |
|
26 | - return $rows; |
|
27 | - } |
|
28 | - public function queryArray( $_query ) { |
|
29 | - $result = $this->stdQuery($_query); |
|
30 | - $rows = []; |
|
31 | - while($row = $result->fetch_array()) |
|
32 | - $rows[] = $row; |
|
33 | - return $rows; |
|
34 | - } |
|
35 | - protected function stdQuery( $_query ) { |
|
36 | - $database = $this->connection; |
|
37 | - $result = $database->query($_query); |
|
38 | - if(!$result) { |
|
39 | - Debug::logStack([ |
|
40 | - "query" => $_query, |
|
41 | - "error" => $database->error |
|
42 | - ]); |
|
43 | - exit(); |
|
44 | - } |
|
45 | - return $result; |
|
46 | - } |
|
4 | + public $connection; |
|
5 | + public function __construct( $_srv, $_db, $_usr, $_pass ) { |
|
6 | + try { |
|
7 | + $this->connection = new mysqli( $_srv, $_usr, $_pass, $_db ); |
|
8 | + } catch( Exception $error ) { |
|
9 | + Debug::log($error->getMessage()); |
|
10 | + exit(); |
|
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->insert_id; |
|
20 | + } |
|
21 | + public function queryFetch( $_query ) { |
|
22 | + $result = $this->stdQuery($_query); |
|
23 | + $rows = []; |
|
24 | + while($row = $result->fetch_assoc()) |
|
25 | + $rows[] = $row; |
|
26 | + return $rows; |
|
27 | + } |
|
28 | + public function queryArray( $_query ) { |
|
29 | + $result = $this->stdQuery($_query); |
|
30 | + $rows = []; |
|
31 | + while($row = $result->fetch_array()) |
|
32 | + $rows[] = $row; |
|
33 | + return $rows; |
|
34 | + } |
|
35 | + protected function stdQuery( $_query ) { |
|
36 | + $database = $this->connection; |
|
37 | + $result = $database->query($_query); |
|
38 | + if(!$result) { |
|
39 | + Debug::logStack([ |
|
40 | + "query" => $_query, |
|
41 | + "error" => $database->error |
|
42 | + ]); |
|
43 | + exit(); |
|
44 | + } |
|
45 | + return $result; |
|
46 | + } |
|
47 | 47 | } |
48 | 48 | ?> |
@@ -1,54 +1,54 @@ |
||
1 | 1 | <?php |
2 | 2 | // requireComponent("../functions/array.php"); |
3 | 3 | class Debug { |
4 | - public static $stack; |
|
5 | - private static $initialized = false; |
|
6 | - private function __construct() {} |
|
7 | - private static function initialize() { |
|
8 | - if (self::$initialized) |
|
9 | - return; |
|
10 | - self::$stack = []; |
|
11 | - self::$initialized = true; |
|
12 | - } |
|
13 | - private static function out( $_object ) { |
|
14 | - if(is_object($_object)) { |
|
15 | - echo "isObject"; |
|
16 | - } else if(is_array($_object)) { |
|
17 | - arrayDump($_object, "Debug"); |
|
18 | - } else { |
|
19 | - echo $_object; |
|
20 | - } |
|
21 | - } |
|
22 | - public static function log( $_object ) { |
|
23 | - self::out(["error" => $_object]); |
|
24 | - } |
|
25 | - public static function logln( $_object ) { |
|
26 | - self::log($_object); |
|
27 | - self::out("<br>"); |
|
28 | - } |
|
29 | - public static function logStack( $_object ) { |
|
30 | - self::out([ |
|
31 | - "position" => self::$stack, |
|
32 | - "error" => $_object |
|
33 | - ]); |
|
34 | - self::out("<br>"); |
|
35 | - } |
|
36 | - public static function push() { |
|
37 | - $debugInfo = debug_backtrace(); |
|
38 | - $debugInfo = [ |
|
39 | - "file" => $debugInfo[1]["file"], |
|
40 | - "line" => $debugInfo[1]["line"], |
|
41 | - "function" => $debugInfo[1]["function"], |
|
42 | - "class" => $debugInfo[1]["class"] |
|
43 | - ]; |
|
44 | - self::$stack[] = $debugInfo; |
|
45 | - } |
|
46 | - public static function pop() { |
|
47 | - if(count(self::$stack)>0) |
|
48 | - array_shift(self::$stack); |
|
49 | - } |
|
50 | - public static function emptyStack() { |
|
51 | - self::$stack = []; |
|
52 | - } |
|
4 | + public static $stack; |
|
5 | + private static $initialized = false; |
|
6 | + private function __construct() {} |
|
7 | + private static function initialize() { |
|
8 | + if (self::$initialized) |
|
9 | + return; |
|
10 | + self::$stack = []; |
|
11 | + self::$initialized = true; |
|
12 | + } |
|
13 | + private static function out( $_object ) { |
|
14 | + if(is_object($_object)) { |
|
15 | + echo "isObject"; |
|
16 | + } else if(is_array($_object)) { |
|
17 | + arrayDump($_object, "Debug"); |
|
18 | + } else { |
|
19 | + echo $_object; |
|
20 | + } |
|
21 | + } |
|
22 | + public static function log( $_object ) { |
|
23 | + self::out(["error" => $_object]); |
|
24 | + } |
|
25 | + public static function logln( $_object ) { |
|
26 | + self::log($_object); |
|
27 | + self::out("<br>"); |
|
28 | + } |
|
29 | + public static function logStack( $_object ) { |
|
30 | + self::out([ |
|
31 | + "position" => self::$stack, |
|
32 | + "error" => $_object |
|
33 | + ]); |
|
34 | + self::out("<br>"); |
|
35 | + } |
|
36 | + public static function push() { |
|
37 | + $debugInfo = debug_backtrace(); |
|
38 | + $debugInfo = [ |
|
39 | + "file" => $debugInfo[1]["file"], |
|
40 | + "line" => $debugInfo[1]["line"], |
|
41 | + "function" => $debugInfo[1]["function"], |
|
42 | + "class" => $debugInfo[1]["class"] |
|
43 | + ]; |
|
44 | + self::$stack[] = $debugInfo; |
|
45 | + } |
|
46 | + public static function pop() { |
|
47 | + if(count(self::$stack)>0) |
|
48 | + array_shift(self::$stack); |
|
49 | + } |
|
50 | + public static function emptyStack() { |
|
51 | + self::$stack = []; |
|
52 | + } |
|
53 | 53 | } |
54 | 54 | ?> |