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