/** * @param $clause * @param array $parameters - first is $statement followed by $parameters * @return $this|SelectQuery */ public function __call($clause, $parameters = array()) { $clause = FluentUtils::toUpperWords($clause); if ($clause == 'GROUP') { $clause = 'GROUP BY'; } if ($clause == 'ORDER') { $clause = 'ORDER BY'; } if ($clause == 'FOOT NOTE') { $clause = "\n--"; } $statement = array_shift($parameters); if (strpos($clause, 'JOIN') !== FALSE) { return $this->addJoinStatements($clause, $statement, $parameters); } return $this->addStatement($clause, $statement, $parameters); }
/** * Get query string * * @param bool $formatted - Return formatted query * * @return string */ public function getQuery($formatted = true) { $query = $this->buildQuery(); if ($formatted) { $query = FluentUtils::formatQuery($query); } return $query; }
/** Fetch all row * * @param string $index specify index column * @param string $selectOnly select columns which could be fetched * * @return array of fetched rows */ public function fetchAll($index = '', $selectOnly = '') { if ($selectOnly) { $this->select(null)->select($index . ', ' . $selectOnly); } if ($index) { $data = array(); foreach ($this as $row) { if (is_object($row)) { $data[$row->{$index}] = $row; } else { $data[$row[$index]] = $row; } } return $data; } else { if (($s = $this->execute()) !== false) { if ($this->convertTypes) { return FluentUtils::convertToNativeTypes($s, $s->fetchAll()); } else { return $s->fetchAll(); } } return $s; } }