| @@ -33,15 +33,17 @@ discard block | ||
| 33 | 33 |      { | 
| 34 | 34 | $this->driverName = 'Mysqli'; | 
| 35 | 35 | |
| 36 | -        if (!array_key_exists("dbchar", $options)) | |
| 37 | - $options["dbchar"] = "utf8"; | |
| 36 | +        if (!array_key_exists("dbchar", $options)) { | |
| 37 | + $options["dbchar"] = "utf8"; | |
| 38 | + } | |
| 38 | 39 | |
| 39 | 40 | parent::__construct($options); | 
| 40 | 41 | |
| 41 | 42 |          $auto_connect = array_key_exists('auto_connect', $options) ? $options["auto_connect"] : true; | 
| 42 | 43 | |
| 43 | - if ($auto_connect) | |
| 44 | - $this->connect(); | |
| 44 | +        if ($auto_connect) { | |
| 45 | + $this->connect(); | |
| 46 | + } | |
| 45 | 47 | } | 
| 46 | 48 | |
| 47 | 49 | /** | 
| @@ -54,13 +56,15 @@ discard block | ||
| 54 | 56 | */ | 
| 55 | 57 | public function connect() | 
| 56 | 58 |      { | 
| 57 | -        if (!extension_loaded('mysqli')) | |
| 58 | -            throw new \RuntimeException("The Mysqli extension is not loaded"); | |
| 59 | +        if (!extension_loaded('mysqli')) { | |
| 60 | +                    throw new \RuntimeException("The Mysqli extension is not loaded"); | |
| 61 | + } | |
| 59 | 62 | |
| 60 | - if (!is_null($this->dbport) && !empty($this->dbport)) | |
| 61 | - $conn = @new \mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname, $this->dbport); | |
| 62 | - else | |
| 63 | - $conn = @new \mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname); | |
| 63 | +        if (!is_null($this->dbport) && !empty($this->dbport)) { | |
| 64 | + $conn = @new \mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname, $this->dbport); | |
| 65 | +        } else { | |
| 66 | + $conn = @new \mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname); | |
| 67 | + } | |
| 64 | 68 | |
| 65 | 69 | if ($conn->connect_errno) | 
| 66 | 70 |          { | 
| @@ -72,8 +76,7 @@ discard block | ||
| 72 | 76 | var_dump(mysqli_connect_errno()); | 
| 73 | 77 | var_dump(mysqli_connect_error()); | 
| 74 | 78 | throw new Exception\ConnectionException(mysqli_connect_error(), mysqli_connect_errno()); | 
| 75 | - } | |
| 76 | - else | |
| 79 | + } else | |
| 77 | 80 |          { | 
| 78 | 81 | $this->dbconn = $conn; | 
| 79 | 82 | $this->dbconn->set_charset($this->dbchar); | 
| @@ -120,13 +123,15 @@ discard block | ||
| 120 | 123 | |
| 121 | 124 | for ($i = 0; $i < $n_params; $i++) | 
| 122 | 125 |              { | 
| 123 | - if (is_string($param_values[$i])) | |
| 124 | - $bind_types .= 's'; | |
| 125 | - else if(is_float($param_values[$i])) | |
| 126 | - $bind_types .= 'd'; | |
| 126 | +                if (is_string($param_values[$i])) { | |
| 127 | + $bind_types .= 's'; | |
| 128 | +                } else if(is_float($param_values[$i])) { | |
| 129 | + $bind_types .= 'd'; | |
| 130 | + } | |
| 127 | 131 | # [POSSIBLE BUG] - To Future revision (What about non-string and non-decimal types ?) | 
| 128 | - else | |
| 129 | - $bind_types .= 's'; | |
| 132 | +                else { | |
| 133 | + $bind_types .= 's'; | |
| 134 | + } | |
| 130 | 135 | |
| 131 | 136 | $bind_values[] = '$param_values[' . $i . ']'; | 
| 132 | 137 | } | 
| @@ -135,8 +140,7 @@ discard block | ||
| 135 | 140 |              eval('$stmt->bind_param(\'' . $bind_types . '\', ' . $values . ');'); | 
| 136 | 141 | |
| 137 | 142 | $r = $stmt->execute(); | 
| 138 | - } | |
| 139 | - else | |
| 143 | + } else | |
| 140 | 144 |          { | 
| 141 | 145 | $prev_error_handler = set_error_handler(['\Drone\Error\ErrorHandler', 'errorControlOperator'], E_ALL); | 
| 142 | 146 | |
| @@ -165,28 +169,33 @@ discard block | ||
| 165 | 169 | * It is useful to prevent rollback transactions on insert statements because | 
| 166 | 170 | * insert statement do not free results. | 
| 167 | 171 | */ | 
| 168 | - if ($res) | |
| 169 | - $this->result = $res; | |
| 172 | +            if ($res) { | |
| 173 | + $this->result = $res; | |
| 174 | + } | |
| 170 | 175 | } | 
| 171 | 176 | |
| 172 | 177 | # identify SELECT, SHOW, DESCRIBE or EXPLAIN queries | 
| 173 | - if (is_object($this->result) && property_exists($this->result, 'num_rows')) | |
| 174 | - $this->numRows = $this->result->num_rows; | |
| 175 | - else | |
| 178 | +        if (is_object($this->result) && property_exists($this->result, 'num_rows')) { | |
| 179 | + $this->numRows = $this->result->num_rows; | |
| 180 | + } else | |
| 176 | 181 |          { | 
| 177 | - if (property_exists($this->dbconn, 'affected_rows') && !$is_stmt_result) | |
| 178 | - $this->rowsAffected = $this->dbconn->affected_rows; | |
| 182 | +            if (property_exists($this->dbconn, 'affected_rows') && !$is_stmt_result) { | |
| 183 | + $this->rowsAffected = $this->dbconn->affected_rows; | |
| 184 | + } | |
| 179 | 185 | } | 
| 180 | 186 | |
| 181 | 187 | # affected_rows return the same of num_rows on select statements! | 
| 182 | - if ($this->numRows > 0) | |
| 183 | - $this->rowsAffected = 0; | |
| 188 | +        if ($this->numRows > 0) { | |
| 189 | + $this->rowsAffected = 0; | |
| 190 | + } | |
| 184 | 191 | |
| 185 | - if (property_exists($this->dbconn, 'field_count')) | |
| 186 | - $this->numFields = $this->dbconn->field_count; | |
| 192 | +        if (property_exists($this->dbconn, 'field_count')) { | |
| 193 | + $this->numFields = $this->dbconn->field_count; | |
| 194 | + } | |
| 187 | 195 | |
| 188 | - if ($this->transac_mode) | |
| 189 | - $this->transac_result = is_null($this->transac_result) ? $this->result: $this->transac_result && $this->result; | |
| 196 | +        if ($this->transac_mode) { | |
| 197 | + $this->transac_result = is_null($this->transac_result) ? $this->result: $this->transac_result && $this->result; | |
| 198 | + } | |
| 190 | 199 | /* | 
| 191 | 200 | * Because mysqli_query() returns FALSE on failure, a mysqli_result object for SELECT, SHOW, DESCRIBE or EXPLAIN queries, | 
| 192 | 201 | * and TRUE for other successful queries, it should be handled to return only objects or resources. | 
| @@ -254,10 +263,10 @@ discard block | ||
| 254 | 263 |              { | 
| 255 | 264 | $data[] = $row; | 
| 256 | 265 | } | 
| 257 | - } | |
| 258 | - else | |
| 259 | - # This error is thrown because of 'execute' method has not been executed. | |
| 266 | +        } else { | |
| 267 | + # This error is thrown because of 'execute' method has not been executed. | |
| 260 | 268 |              throw new \LogicException('There are not data in the buffer!'); | 
| 269 | + } | |
| 261 | 270 | |
| 262 | 271 | $this->arrayResult = $data; | 
| 263 | 272 | |
| @@ -272,7 +281,8 @@ discard block | ||
| 272 | 281 | public function __destruct() | 
| 273 | 282 |      { | 
| 274 | 283 | # prevent "Property access is not allowed yet" with @ on failure connections | 
| 275 | - if ($this->dbconn !== false && !is_null($this->dbconn)) | |
| 276 | - @$this->dbconn->close(); | |
| 284 | +        if ($this->dbconn !== false && !is_null($this->dbconn)) { | |
| 285 | + @$this->dbconn->close(); | |
| 286 | + } | |
| 277 | 287 | } | 
| 278 | 288 | } | 
| 279 | 289 | \ No newline at end of file |