@@ -31,15 +31,17 @@ discard block |
||
31 | 31 | */ |
32 | 32 | public function __construct($options) |
33 | 33 | { |
34 | - if (!array_key_exists("dbchar", $options)) |
|
35 | - $options["dbchar"] = "UTF-8"; |
|
34 | + if (!array_key_exists("dbchar", $options)) { |
|
35 | + $options["dbchar"] = "UTF-8"; |
|
36 | + } |
|
36 | 37 | |
37 | 38 | parent::__construct($options); |
38 | 39 | |
39 | 40 | $auto_connect = array_key_exists('auto_connect', $options) ? $options["auto_connect"] : true; |
40 | 41 | |
41 | - if ($auto_connect) |
|
42 | - $this->connect(); |
|
42 | + if ($auto_connect) { |
|
43 | + $this->connect(); |
|
44 | + } |
|
43 | 45 | } |
44 | 46 | |
45 | 47 | /** |
@@ -52,11 +54,13 @@ discard block |
||
52 | 54 | */ |
53 | 55 | public function connect() |
54 | 56 | { |
55 | - if (!extension_loaded('sqlsrv')) |
|
56 | - throw new \RuntimeException("The Sqlsrv extension is not loaded"); |
|
57 | + if (!extension_loaded('sqlsrv')) { |
|
58 | + throw new \RuntimeException("The Sqlsrv extension is not loaded"); |
|
59 | + } |
|
57 | 60 | |
58 | - if (!is_null($this->dbport) && !empty($this->dbport)) |
|
59 | - $this->dbhost .= ', ' . $this->dbport; |
|
61 | + if (!is_null($this->dbport) && !empty($this->dbport)) { |
|
62 | + $this->dbhost .= ', ' . $this->dbport; |
|
63 | + } |
|
60 | 64 | |
61 | 65 | $db_info = array("Database" => $this->dbname, "UID" => $this->dbuser, "PWD" => $this->dbpass, "CharacterSet" => $this->dbchar); |
62 | 66 | $conn = sqlsrv_connect($this->dbhost, $db_info); |
@@ -137,13 +141,13 @@ discard block |
||
137 | 141 | } |
138 | 142 | |
139 | 143 | $exec = sqlsrv_execute($stmt); |
140 | - } |
|
141 | - else |
|
144 | + } else |
|
142 | 145 | { |
143 | - if ($isSelectStm) |
|
144 | - $exec = $this->result = sqlsrv_query($this->dbconn, $sql, $params, array( "Scrollable" => SQLSRV_CURSOR_KEYSET )); |
|
145 | - else |
|
146 | - $exec = $this->result = sqlsrv_query($this->dbconn, $sql, $params); |
|
146 | + if ($isSelectStm) { |
|
147 | + $exec = $this->result = sqlsrv_query($this->dbconn, $sql, $params, array( "Scrollable" => SQLSRV_CURSOR_KEYSET )); |
|
148 | + } else { |
|
149 | + $exec = $this->result = sqlsrv_query($this->dbconn, $sql, $params); |
|
150 | + } |
|
147 | 151 | } |
148 | 152 | |
149 | 153 | if ($exec === false) |
@@ -163,11 +167,13 @@ discard block |
||
163 | 167 | $this->numRows = sqlsrv_has_rows($this->result) ? sqlsrv_num_rows($this->result) : $this->numRows; |
164 | 168 | $this->numFields = sqlsrv_num_fields($this->result); |
165 | 169 | |
166 | - if ($isInsertStm || $isUpdateStm || $isDeleteStm) |
|
167 | - $this->rowsAffected = sqlsrv_rows_affected($this->result); |
|
170 | + if ($isInsertStm || $isUpdateStm || $isDeleteStm) { |
|
171 | + $this->rowsAffected = sqlsrv_rows_affected($this->result); |
|
172 | + } |
|
168 | 173 | |
169 | - if ($this->transac_mode) |
|
170 | - $this->transac_result = is_null($this->transac_result) ? $this->result: $this->transac_result && $this->result; |
|
174 | + if ($this->transac_mode) { |
|
175 | + $this->transac_result = is_null($this->transac_result) ? $this->result: $this->transac_result && $this->result; |
|
176 | + } |
|
171 | 177 | |
172 | 178 | return $this->result; |
173 | 179 | } |
@@ -234,9 +240,8 @@ discard block |
||
234 | 240 | { |
235 | 241 | $data[] = $row; |
236 | 242 | } |
237 | - } |
|
238 | - else |
|
239 | - /* |
|
243 | + } else { |
|
244 | + /* |
|
240 | 245 | * "This kind of exception should lead directly to a fix in your code" |
241 | 246 | * So much production tests tell us this error is throwed because developers |
242 | 247 | * execute toArray() before execute(). |
@@ -244,6 +249,7 @@ discard block |
||
244 | 249 | * Ref: http://php.net/manual/en/class.logicexception.php |
245 | 250 | */ |
246 | 251 | throw new \LogicException('There are not data in the buffer!'); |
252 | + } |
|
247 | 253 | |
248 | 254 | $this->arrayResult = $data; |
249 | 255 | |
@@ -257,7 +263,8 @@ discard block |
||
257 | 263 | */ |
258 | 264 | public function __destruct() |
259 | 265 | { |
260 | - if ($this->dbconn) |
|
261 | - sqlsrv_close($this->dbconn); |
|
266 | + if ($this->dbconn) { |
|
267 | + sqlsrv_close($this->dbconn); |
|
268 | + } |
|
262 | 269 | } |
263 | 270 | } |
264 | 271 | \ No newline at end of file |