@@ -22,28 +22,28 @@ discard block |
||
22 | 22 | $this->qb = new QueryBuilder(); |
23 | 23 | } |
24 | 24 | |
25 | - public function createQuery($row){ |
|
25 | + public function createQuery($row) { |
|
26 | 26 | $ar = []; |
27 | - if(isset($row) && isset($row->id) && $row->id > 0 ){ |
|
27 | + if (isset($row) && isset($row->id) && $row->id > 0) { |
|
28 | 28 | $query = "UPDATE ".$this->table()." SET "; |
29 | - foreach($row as $key => $val){ |
|
29 | + foreach ($row as $key => $val) { |
|
30 | 30 | $ar[':'.$key] = $val; |
31 | - if($key == 'id') continue; |
|
32 | - $query.= $this->qb->quote($key)." =:".$key.","; |
|
31 | + if ($key == 'id') continue; |
|
32 | + $query .= $this->qb->quote($key)." =:".$key.","; |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | $query = rtrim($query, ","); |
36 | - $query.= " WHERE ".$this->qb->quote('id')."=:id"; |
|
36 | + $query .= " WHERE ".$this->qb->quote('id')."=:id"; |
|
37 | 37 | |
38 | 38 | return ['query' => $query, 'data' => $ar]; |
39 | 39 | } |
40 | 40 | |
41 | 41 | $queryVal = ''; |
42 | 42 | $query = "INSERT INTO ".$this->table()." ("; |
43 | - foreach($row as $key => $val){ |
|
44 | - $query.= $this->qb->quote($key).", "; |
|
43 | + foreach ($row as $key => $val) { |
|
44 | + $query .= $this->qb->quote($key).", "; |
|
45 | 45 | $ar[$key] = $val; |
46 | - $queryVal.= ":".$key.", "; |
|
46 | + $queryVal .= ":".$key.", "; |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | $query = rtrim($query, ", ").") VALUES (".$queryVal.rtrim($query, ", ").") "; |
@@ -69,10 +69,10 @@ discard block |
||
69 | 69 | |
70 | 70 | list($query, $data) = $this->createQuery($row); |
71 | 71 | |
72 | - try{ |
|
72 | + try { |
|
73 | 73 | $stmt = Connection::get()->prepare($qb->queryPrefix($query)); |
74 | 74 | $stmt->execute($data); |
75 | - } catch(Exception $e){ |
|
75 | + } catch (Exception $e) { |
|
76 | 76 | throw new Exception($e->getMessage()); |
77 | 77 | } |
78 | 78 |