@@ -50,16 +50,16 @@ |
||
| 50 | 50 | return $destination; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Turn the stadClass object to the type of calling Model |
|
| 55 | - * |
|
| 56 | - * @param String $destination |
|
| 57 | - * @param Object $sourceObject |
|
| 58 | - * @return Object $destination |
|
| 59 | - * |
|
| 60 | - * @author RN Kushwaha <[email protected]> |
|
| 61 | - * @since v0.0.5 |
|
| 62 | - */ |
|
| 53 | + /** |
|
| 54 | + * Turn the stadClass object to the type of calling Model |
|
| 55 | + * |
|
| 56 | + * @param String $destination |
|
| 57 | + * @param Object $sourceObject |
|
| 58 | + * @return Object $destination |
|
| 59 | + * |
|
| 60 | + * @author RN Kushwaha <[email protected]> |
|
| 61 | + * @since v0.0.5 |
|
| 62 | + */ |
|
| 63 | 63 | public function turnObjects($destination, $data) |
| 64 | 64 | { |
| 65 | 65 | $destination = new $destination(); |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | private function whereAddedCondition($conditions = []){ |
| 39 | - return $this->whereAdded === false && count($conditions); |
|
| 39 | + return $this->whereAdded === false && count($conditions); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | public function buildWhereQuery($conditions = []) |
@@ -48,8 +48,8 @@ discard block |
||
| 48 | 48 | |
| 49 | 49 | $firstTime = true; |
| 50 | 50 | if ($this->whereAddedCondition($conditions)) { |
| 51 | - $whereQuery[] = 'WHERE'; |
|
| 52 | - $this->whereAdded = true; |
|
| 51 | + $whereQuery[] = 'WHERE'; |
|
| 52 | + $this->whereAdded = true; |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | foreach ($conditions as $where) { |
@@ -79,37 +79,37 @@ |
||
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | private function buildLimitQuery($limit, $offset, $query = []){ |
| 82 | - $limitQuery = []; |
|
| 83 | - if (!empty($limit)) { |
|
| 84 | - $query[] = 'LIMIT'; |
|
| 82 | + $limitQuery = []; |
|
| 83 | + if (!empty($limit)) { |
|
| 84 | + $query[] = 'LIMIT'; |
|
| 85 | 85 | |
| 86 | - if (!empty($offset)) { |
|
| 87 | - $query[] = $offset.','; |
|
| 88 | - } |
|
| 86 | + if (!empty($offset)) { |
|
| 87 | + $query[] = $offset.','; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - $query[] = $limit; |
|
| 91 | - } |
|
| 90 | + $query[] = $limit; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - if (count($limitQuery)) { |
|
| 94 | - $query = array_merge($query, $limitQuery); |
|
| 95 | - } |
|
| 96 | - return $query; |
|
| 93 | + if (count($limitQuery)) { |
|
| 94 | + $query = array_merge($query, $limitQuery); |
|
| 95 | + } |
|
| 96 | + return $query; |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | public function query($query, $fetchRows){ |
| 100 | - try { |
|
| 101 | - $obj = Connection::get()->query($this->queryPrefix($query), \PDO::FETCH_OBJ); |
|
| 102 | - |
|
| 103 | - if ($fetchRows == 'count') { |
|
| 104 | - $obj = $obj->fetchColumn(); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - return $obj; |
|
| 108 | - } catch (\PDOException $ex) { |
|
| 109 | - throw new \PDOException($ex->getMessage(), 1); |
|
| 110 | - } catch (Exception $e) { |
|
| 111 | - throw new Exception($e->getMessage(), 1); |
|
| 112 | - } |
|
| 100 | + try { |
|
| 101 | + $obj = Connection::get()->query($this->queryPrefix($query), \PDO::FETCH_OBJ); |
|
| 102 | + |
|
| 103 | + if ($fetchRows == 'count') { |
|
| 104 | + $obj = $obj->fetchColumn(); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + return $obj; |
|
| 108 | + } catch (\PDOException $ex) { |
|
| 109 | + throw new \PDOException($ex->getMessage(), 1); |
|
| 110 | + } catch (Exception $e) { |
|
| 111 | + throw new Exception($e->getMessage(), 1); |
|
| 112 | + } |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | public function buildQuery(array $params) |
@@ -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 = []; |