@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public function PDO() |
34 | 34 | { |
35 | - if(empty($this->conn)) { |
|
35 | + if (empty($this->conn)) { |
|
36 | 36 | try { |
37 | 37 | $this->conn = new PDO( |
38 | 38 | $this->config['driver'] . ":host=" . |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | $this->config['password'], |
45 | 45 | $this->config['options'] |
46 | 46 | ); |
47 | - } catch(PDOException $exception) { |
|
47 | + } catch (PDOException $exception) { |
|
48 | 48 | echo json_encode( |
49 | 49 | ['error' => |
50 | 50 | [ |
@@ -156,13 +156,17 @@ |
||
156 | 156 | switch (!is_object($this->data) && $count = count($this->data)) { |
157 | 157 | case (!isset($this->data[0]) && !empty($this->data)): |
158 | 158 | foreach($this->excepts as $except) { |
159 | - if(isset($this->data[$except])) unset($this->data[$except]); |
|
159 | + if(isset($this->data[$except])) { |
|
160 | + unset($this->data[$except]); |
|
161 | + } |
|
160 | 162 | } |
161 | 163 | break; |
162 | 164 | case ($count >= 2 && isset($this->data[0])): |
163 | 165 | foreach($this->excepts as $except) { |
164 | 166 | for($i = 0; $i < $count; $i++) { |
165 | - if(isset($this->data[$i][$except])) unset($this->data[$i][$except]); |
|
167 | + if(isset($this->data[$i][$except])) { |
|
168 | + unset($this->data[$i][$except]); |
|
169 | + } |
|
166 | 170 | } |
167 | 171 | } |
168 | 172 | break; |
@@ -166,8 +166,8 @@ |
||
166 | 166 | } |
167 | 167 | } |
168 | 168 | break; |
169 | - default: |
|
170 | - return []; |
|
169 | + default: |
|
170 | + return []; |
|
171 | 171 | } |
172 | 172 | } |
173 | 173 | } |
@@ -152,17 +152,17 @@ discard block |
||
152 | 152 | */ |
153 | 153 | private function deny() |
154 | 154 | { |
155 | - if(!empty($this->excepts)) { |
|
155 | + if (!empty($this->excepts)) { |
|
156 | 156 | switch (!is_object($this->data) && $count = count($this->data)) { |
157 | 157 | case (!isset($this->data[0]) && !empty($this->data)): |
158 | - foreach($this->excepts as $except) { |
|
159 | - if(isset($this->data[$except])) unset($this->data[$except]); |
|
158 | + foreach ($this->excepts as $except) { |
|
159 | + if (isset($this->data[$except])) unset($this->data[$except]); |
|
160 | 160 | } |
161 | 161 | break; |
162 | 162 | case ($count >= 2 && isset($this->data[0])): |
163 | - foreach($this->excepts as $except) { |
|
164 | - for($i = 0; $i < $count; $i++) { |
|
165 | - if(isset($this->data[$i][$except])) unset($this->data[$i][$except]); |
|
163 | + foreach ($this->excepts as $except) { |
|
164 | + for ($i = 0; $i < $count; $i++) { |
|
165 | + if (isset($this->data[$i][$except])) unset($this->data[$i][$except]); |
|
166 | 166 | } |
167 | 167 | } |
168 | 168 | break; |
@@ -180,11 +180,10 @@ discard block |
||
180 | 180 | try { |
181 | 181 | $execute = $this->conn->query("SELECT {$this->params} FROM {$this->table} {$this->where} {$this->order} {$this->limit} {$this->offset}"); |
182 | 182 | $execute->rowCount() > 1 ? |
183 | - $this->data = ($this->type ? $execute->fetchAll(PDO::FETCH_CLASS, static::class) : $execute->fetchAll(PDO::FETCH_ASSOC)) : |
|
184 | - $this->data = ($this->type ? $execute->fetchObject(static::class) : $execute->fetch(PDO::FETCH_ASSOC)); |
|
183 | + $this->data = ($this->type ? $execute->fetchAll(PDO::FETCH_CLASS, static::class) : $execute->fetchAll(PDO::FETCH_ASSOC)) : $this->data = ($this->type ? $execute->fetchObject(static::class) : $execute->fetch(PDO::FETCH_ASSOC)); |
|
185 | 184 | $this->deny(); |
186 | 185 | return $this->data; |
187 | - } catch(PDOException $exc) { |
|
186 | + } catch (PDOException $exc) { |
|
188 | 187 | return $exc->getMessage(); |
189 | 188 | } |
190 | 189 | } |
@@ -11,28 +11,28 @@ |
||
11 | 11 | $params = explode(', ', $params); |
12 | 12 | $data = []; |
13 | 13 | $paramsCount = count($params); $dataCount = count($data); |
14 | - for($i = 0; $i < $paramsCount; $i++) { |
|
15 | - $data[$i] = ":".$params[$i][0].$params[$i][1].$params[$i][2].", "; |
|
14 | + for ($i = 0; $i < $paramsCount; $i++) { |
|
15 | + $data[$i] = ":" . $params[$i][0] . $params[$i][1] . $params[$i][2] . ", "; |
|
16 | 16 | } |
17 | 17 | $result = ''; |
18 | 18 | $final = array_map(null, $params, $data); |
19 | - foreach($final as $key => $vals) { |
|
20 | - foreach($vals as $chave => $val) { |
|
19 | + foreach ($final as $key => $vals) { |
|
20 | + foreach ($vals as $chave => $val) { |
|
21 | 21 | $result .= str_replace(':', ' = :', $val); |
22 | 22 | } |
23 | 23 | } |
24 | 24 | $result = rtrim($result, ', '); |
25 | - $sql = $this->conn->prepare("UPDATE $table SET $result ". (isset($where) ? "WHERE ". $where : '')); |
|
26 | - for($i = 0; $i < $paramsCount; $i++) { |
|
27 | - $data[$i] = ":".$params[$i][0].$params[$i][1].$params[$i][2]; |
|
25 | + $sql = $this->conn->prepare("UPDATE $table SET $result " . (isset($where) ? "WHERE " . $where : '')); |
|
26 | + for ($i = 0; $i < $paramsCount; $i++) { |
|
27 | + $data[$i] = ":" . $params[$i][0] . $params[$i][1] . $params[$i][2]; |
|
28 | 28 | } |
29 | - for($i = 0; $i < $dataCount; $i++) { |
|
29 | + for ($i = 0; $i < $dataCount; $i++) { |
|
30 | 30 | $sql->bindParam($data[$i], $values[$i]); |
31 | 31 | } |
32 | - if($sql->execute()) { |
|
32 | + if ($sql->execute()) { |
|
33 | 33 | return true; |
34 | 34 | } else { |
35 | - echo "Erro:". $sql->errorInfo(); |
|
35 | + echo "Erro:" . $sql->errorInfo(); |
|
36 | 36 | } |
37 | 37 | } |
38 | 38 | } |
39 | 39 | \ No newline at end of file |