|
@@ -32,7 +32,7 @@ discard block |
|
|
block discarded – undo |
|
32
|
32
|
|
|
33
|
33
|
use \Exception; |
|
34
|
34
|
|
|
35
|
|
-require_once dirname(__DIR__) . "/config/_config.php"; |
|
|
35
|
+require_once dirname(__DIR__)."/config/_config.php"; |
|
36
|
36
|
|
|
37
|
37
|
/** |
|
38
|
38
|
* This class is a singleton for establishing a connection to the database |
|
@@ -60,14 +60,14 @@ discard block |
|
|
block discarded – undo |
|
60
|
60
|
case "EXTERNAL": |
|
61
|
61
|
case "FRONTEND": |
|
62
|
62
|
case "DIAGNOSTICS": |
|
63
|
|
- if (!isset(self::${"instance" . $theDb})) { |
|
|
63
|
+ if (!isset(self::${"instance".$theDb})) { |
|
64
|
64
|
$class = __CLASS__; |
|
65
|
|
- self::${"instance" . $theDb} = new $class($database); |
|
66
|
|
- DBConnection::${"instance" . $theDb}->databaseInstance = $theDb; |
|
|
65
|
+ self::${"instance".$theDb} = new $class($database); |
|
|
66
|
+ DBConnection::${"instance".$theDb}->databaseInstance = $theDb; |
|
67
|
67
|
} |
|
68
|
|
- return self::${"instance" . $theDb}; |
|
|
68
|
+ return self::${"instance".$theDb}; |
|
69
|
69
|
default: |
|
70
|
|
- throw new Exception("This type of database (" . strtoupper($database) . ") is not known!"); |
|
|
70
|
+ throw new Exception("This type of database (".strtoupper($database).") is not known!"); |
|
71
|
71
|
} |
|
72
|
72
|
} |
|
73
|
73
|
|
|
@@ -106,18 +106,18 @@ discard block |
|
|
block discarded – undo |
|
106
|
106
|
} |
|
107
|
107
|
} |
|
108
|
108
|
// log exact query to debug log, if log level is at 5 |
|
109
|
|
- $this->loggerInstance->debug(5, "DB ATTEMPT: " . $querystring . "\n"); |
|
|
109
|
+ $this->loggerInstance->debug(5, "DB ATTEMPT: ".$querystring."\n"); |
|
110
|
110
|
if ($types !== NULL) { |
|
111
|
|
- $this->loggerInstance->debug(5, "Argument type sequence: $types, parameters are: " . print_r($arguments, true)); |
|
|
111
|
+ $this->loggerInstance->debug(5, "Argument type sequence: $types, parameters are: ".print_r($arguments, true)); |
|
112
|
112
|
} |
|
113
|
113
|
|
|
114
|
114
|
if ($this->connection->connect_error) { |
|
115
|
|
- throw new Exception("ERROR: Cannot send query to $this->databaseInstance database (no connection, error number" . $this->connection->connect_error . ")!"); |
|
|
115
|
+ throw new Exception("ERROR: Cannot send query to $this->databaseInstance database (no connection, error number".$this->connection->connect_error.")!"); |
|
116
|
116
|
} |
|
117
|
117
|
if ($types === NULL) { |
|
118
|
118
|
$result = $this->connection->query($querystring); |
|
119
|
119
|
if ($result === FALSE) { |
|
120
|
|
- throw new Exception("DB: Unable to execute simple statement! Error was --> " . $this->connection->error . " <--"); |
|
|
120
|
+ throw new Exception("DB: Unable to execute simple statement! Error was --> ".$this->connection->error." <--"); |
|
121
|
121
|
} |
|
122
|
122
|
} else { |
|
123
|
123
|
// fancy! prepared statement with dedicated argument list |
|
@@ -130,7 +130,7 @@ discard block |
|
|
block discarded – undo |
|
130
|
130
|
} |
|
131
|
131
|
$prepResult = $statementObject->prepare($querystring); |
|
132
|
132
|
if ($prepResult === FALSE) { |
|
133
|
|
- throw new Exception("DB: Unable to prepare statement! Statement was --> $querystring <--, error was --> " . $statementObject->error . " <--."); |
|
|
133
|
+ throw new Exception("DB: Unable to prepare statement! Statement was --> $querystring <--, error was --> ".$statementObject->error." <--."); |
|
134
|
134
|
} |
|
135
|
135
|
|
|
136
|
136
|
// we have a variable number of arguments packed into the ... array |
|
@@ -142,11 +142,11 @@ discard block |
|
|
block discarded – undo |
|
142
|
142
|
array_unshift($localArray, $types); |
|
143
|
143
|
$retval = call_user_func_array([$statementObject, "bind_param"], $localArray); |
|
144
|
144
|
if ($retval === FALSE) { |
|
145
|
|
- throw new Exception("DB: Unable to bind parameters to prepared statement! Argument array was --> " . var_export($localArray, TRUE) . " <--. Error was --> " . $statementObject->error . " <--"); |
|
|
145
|
+ throw new Exception("DB: Unable to bind parameters to prepared statement! Argument array was --> ".var_export($localArray, TRUE)." <--. Error was --> ".$statementObject->error." <--"); |
|
146
|
146
|
} |
|
147
|
147
|
$result = $statementObject->execute(); |
|
148
|
148
|
if ($result === FALSE) { |
|
149
|
|
- throw new Exception("DB: Unable to execute prepared statement! Error was --> " . $statementObject->error . " <--"); |
|
|
149
|
+ throw new Exception("DB: Unable to execute prepared statement! Error was --> ".$statementObject->error." <--"); |
|
150
|
150
|
} |
|
151
|
151
|
$selectResult = $statementObject->get_result(); |
|
152
|
152
|
if ($selectResult !== FALSE) { |
|
@@ -158,14 +158,14 @@ discard block |
|
|
block discarded – undo |
|
158
|
158
|
|
|
159
|
159
|
// all cases where $result could be FALSE have been caught earlier |
|
160
|
160
|
if ($this->connection->errno) { |
|
161
|
|
- throw new Exception("ERROR: Cannot execute query in $this->databaseInstance database - (hopefully escaped) query was '$querystring', errno was " . $this->connection->errno . "!"); |
|
|
161
|
+ throw new Exception("ERROR: Cannot execute query in $this->databaseInstance database - (hopefully escaped) query was '$querystring', errno was ".$this->connection->errno."!"); |
|
162
|
162
|
} |
|
163
|
163
|
|
|
164
|
164
|
|
|
165
|
165
|
if ($isMoreThanSelect) { |
|
166
|
|
- $this->loggerInstance->writeSQLAudit("[DB: " . strtoupper($this->databaseInstance) . "] " . $querystring); |
|
|
166
|
+ $this->loggerInstance->writeSQLAudit("[DB: ".strtoupper($this->databaseInstance)."] ".$querystring); |
|
167
|
167
|
if ($types !== NULL) { |
|
168
|
|
- $this->loggerInstance->writeSQLAudit("Argument type sequence: $types, parameters are: " . print_r($arguments, true)); |
|
|
168
|
+ $this->loggerInstance->writeSQLAudit("Argument type sequence: $types, parameters are: ".print_r($arguments, true)); |
|
169
|
169
|
} |
|
170
|
170
|
} |
|
171
|
171
|
return $result; |
|
@@ -249,7 +249,7 @@ discard block |
|
|
block discarded – undo |
|
249
|
249
|
$databaseCapitalised = strtoupper($database); |
|
250
|
250
|
$this->connection = new \mysqli(CONFIG['DB'][$databaseCapitalised]['host'], CONFIG['DB'][$databaseCapitalised]['user'], CONFIG['DB'][$databaseCapitalised]['pass'], CONFIG['DB'][$databaseCapitalised]['db']); |
|
251
|
251
|
if ($this->connection->connect_error) { |
|
252
|
|
- throw new Exception("ERROR: Unable to connect to $database database! This is a fatal error, giving up (error number " . $this->connection->connect_errno . ")."); |
|
|
252
|
+ throw new Exception("ERROR: Unable to connect to $database database! This is a fatal error, giving up (error number ".$this->connection->connect_errno.")."); |
|
253
|
253
|
} |
|
254
|
254
|
|
|
255
|
255
|
if ($databaseCapitalised == "EXTERNAL" && CONFIG_CONFASSISTANT['CONSORTIUM']['name'] == "eduroam" && isset(CONFIG_CONFASSISTANT['CONSORTIUM']['deployment-voodoo']) && CONFIG_CONFASSISTANT['CONSORTIUM']['deployment-voodoo'] == "Operations Team") { |