@@ -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, ", ").") "; |
@@ -68,10 +68,10 @@ discard block |
||
| 68 | 68 | |
| 69 | 69 | list($query, $data) = $this->createQuery($row); |
| 70 | 70 | |
| 71 | - try{ |
|
| 71 | + try { |
|
| 72 | 72 | $stmt = Connection::get()->prepare($this->qb->queryPrefix($query)); |
| 73 | 73 | $stmt->execute($data); |
| 74 | - } catch(Exception $e){ |
|
| 74 | + } catch (Exception $e) { |
|
| 75 | 75 | throw new Exception($e->getMessage()); |
| 76 | 76 | } |
| 77 | 77 | |
@@ -28,7 +28,9 @@ |
||
| 28 | 28 | $query = "UPDATE ".$this->table." SET "; |
| 29 | 29 | foreach($row as $key => $val){ |
| 30 | 30 | $ar[':'.$key] = $val; |
| 31 | - if($key == 'id') continue; |
|
| 31 | + if($key == 'id') { |
|
| 32 | + continue; |
|
| 33 | + } |
|
| 32 | 34 | $query.= $this->qb->quote($key)." =:".$key.","; |
| 33 | 35 | } |
| 34 | 36 | |