@@ -32,7 +32,7 @@ |
||
| 32 | 32 | { |
| 33 | 33 | $ar = []; |
| 34 | 34 | if(!count($whereQuery)){ |
| 35 | - return $ar; |
|
| 35 | + return $ar; |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | foreach ($whereQuery as $where) { |
@@ -26,14 +26,14 @@ |
||
| 26 | 26 | * @since v0.0.8 |
| 27 | 27 | */ |
| 28 | 28 | public function update( |
| 29 | - $row, |
|
| 30 | - $table, |
|
| 31 | - $where, |
|
| 32 | - $whereRaw, |
|
| 33 | - $whereIn, |
|
| 34 | - $whereNotIn, |
|
| 35 | - $whereNull, |
|
| 36 | - $whereNotNull |
|
| 29 | + $row, |
|
| 30 | + $table, |
|
| 31 | + $where, |
|
| 32 | + $whereRaw, |
|
| 33 | + $whereIn, |
|
| 34 | + $whereNotIn, |
|
| 35 | + $whereNull, |
|
| 36 | + $whereNotNull |
|
| 37 | 37 | ): bool |
| 38 | 38 | { |
| 39 | 39 | $wqb = new WhereQueryBuilder(); |
@@ -65,7 +65,7 @@ |
||
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | private function checkMultipleInsert($rows = []){ |
| 68 | - return is_array($rows) && isset($rows[0]) && is_array($rows[0]); |
|
| 68 | + return is_array($rows) && isset($rows[0]) && is_array($rows[0]); |
|
| 69 | 69 | } |
| 70 | 70 | /** |
| 71 | 71 | * It inserts the new rows |
@@ -26,13 +26,13 @@ |
||
| 26 | 26 | * @since v0.0.8 |
| 27 | 27 | */ |
| 28 | 28 | public function delete( |
| 29 | - $table, |
|
| 30 | - $where, |
|
| 31 | - $whereRaw, |
|
| 32 | - $whereIn, |
|
| 33 | - $whereNotIn, |
|
| 34 | - $whereNull, |
|
| 35 | - $whereNotNull |
|
| 29 | + $table, |
|
| 30 | + $where, |
|
| 31 | + $whereRaw, |
|
| 32 | + $whereIn, |
|
| 33 | + $whereNotIn, |
|
| 34 | + $whereNull, |
|
| 35 | + $whereNotNull |
|
| 36 | 36 | ): bool |
| 37 | 37 | { |
| 38 | 38 | $wqb = new WhereQueryBuilder(); |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | class PrepareQueryBuilder extends QueryBuilder |
| 20 | 20 | { |
| 21 | 21 | private function checkCountable($results = null ): bool{ |
| 22 | - return (is_array($results) || is_object($results)) && count($results); |
|
| 22 | + return (is_array($results) || is_object($results)) && count($results); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | /** |
@@ -31,33 +31,33 @@ discard block |
||
| 31 | 31 | * @author RN Kushwaha <[email protected]> |
| 32 | 32 | * @since v0.0.5 |
| 33 | 33 | */ |
| 34 | - public function prepare($where, $className, $query, $fetchRows = 'all') |
|
| 35 | - { |
|
| 36 | - $wqp = new WhereQueryParser(); |
|
| 37 | - $util = new Utils(); |
|
| 38 | - $rows = null; |
|
| 39 | - |
|
| 40 | - try { |
|
| 41 | - $ar = $wqp->parseWhereQuery($where); |
|
| 42 | - $stmt = Connection::get()->prepare($this->queryPrefix($query)); |
|
| 43 | - $stmt->execute($ar); |
|
| 44 | - |
|
| 45 | - if ($fetchRows == 'first') { |
|
| 46 | - $results = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
| 47 | - } else{ |
|
| 48 | - $results = $stmt->fetchAll(\PDO::FETCH_ASSOC); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - if($this->checkCountable($results) ){ |
|
| 52 | - // now turn this stdClass object to the object type of calling model |
|
| 53 | - $rows = $util->turnObjects($className, $results); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - return $rows; |
|
| 57 | - } catch (\PDOException $ex) { |
|
| 58 | - throw new \PDOException($ex->getMessage(), 1); |
|
| 59 | - } catch (Exception $e) { |
|
| 60 | - throw new Exception($e->getMessage(), 1); |
|
| 61 | - } |
|
| 62 | - } |
|
| 34 | + public function prepare($where, $className, $query, $fetchRows = 'all') |
|
| 35 | + { |
|
| 36 | + $wqp = new WhereQueryParser(); |
|
| 37 | + $util = new Utils(); |
|
| 38 | + $rows = null; |
|
| 39 | + |
|
| 40 | + try { |
|
| 41 | + $ar = $wqp->parseWhereQuery($where); |
|
| 42 | + $stmt = Connection::get()->prepare($this->queryPrefix($query)); |
|
| 43 | + $stmt->execute($ar); |
|
| 44 | + |
|
| 45 | + if ($fetchRows == 'first') { |
|
| 46 | + $results = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
| 47 | + } else{ |
|
| 48 | + $results = $stmt->fetchAll(\PDO::FETCH_ASSOC); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + if($this->checkCountable($results) ){ |
|
| 52 | + // now turn this stdClass object to the object type of calling model |
|
| 53 | + $rows = $util->turnObjects($className, $results); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + return $rows; |
|
| 57 | + } catch (\PDOException $ex) { |
|
| 58 | + throw new \PDOException($ex->getMessage(), 1); |
|
| 59 | + } catch (Exception $e) { |
|
| 60 | + throw new Exception($e->getMessage(), 1); |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | 63 | } |
@@ -23,16 +23,16 @@ |
||
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | public function buildQueryStrSingleFromArr($row = []){ |
| 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 = []; |
@@ -374,14 +374,14 @@ discard block |
||
| 374 | 374 | public function update($row) |
| 375 | 375 | { |
| 376 | 376 | $result = (new UpdateQueryBuilder())->update( |
| 377 | - $row, |
|
| 378 | - $this->table, |
|
| 379 | - $this->where, |
|
| 380 | - $this->whereRaw, |
|
| 381 | - $this->whereIn, |
|
| 382 | - $this->whereNotIn, |
|
| 383 | - $this->whereNull, |
|
| 384 | - $this->whereNotNull |
|
| 377 | + $row, |
|
| 378 | + $this->table, |
|
| 379 | + $this->where, |
|
| 380 | + $this->whereRaw, |
|
| 381 | + $this->whereIn, |
|
| 382 | + $this->whereNotIn, |
|
| 383 | + $this->whereNull, |
|
| 384 | + $this->whereNotNull |
|
| 385 | 385 | ); |
| 386 | 386 | |
| 387 | 387 | $this->reset(); |
@@ -420,13 +420,13 @@ discard block |
||
| 420 | 420 | public function delete() |
| 421 | 421 | { |
| 422 | 422 | $result = (new DeleteQueryBuilder())->delete( |
| 423 | - $this->table, |
|
| 424 | - $this->where, |
|
| 425 | - $this->whereRaw, |
|
| 426 | - $this->whereIn, |
|
| 427 | - $this->whereNotIn, |
|
| 428 | - $this->whereNull, |
|
| 429 | - $this->whereNotNull |
|
| 423 | + $this->table, |
|
| 424 | + $this->where, |
|
| 425 | + $this->whereRaw, |
|
| 426 | + $this->whereIn, |
|
| 427 | + $this->whereNotIn, |
|
| 428 | + $this->whereNull, |
|
| 429 | + $this->whereNotNull |
|
| 430 | 430 | ); |
| 431 | 431 | |
| 432 | 432 | $this->reset(); |