public function sql(&$returnParameters = "") { if ($this->sqlString) { return $this->sqlString; } $query = $this->getQuery(); $groupQuery = $this->getGrounpQuery(); $orderQuery = $this->getOrderQuery(); $joinQuery = $this->getJoinQuery(); $sql = $this->getSelectQuery(); $sql .= ' from ' . $this->table . ' as ' . $this->getAlias(); if ($joinQuery) { $sql .= $this->fullJoinQuery; } if ($query) { if (substr($query, 0, 4) == " and") { $query = substr($query, 4); } $sql .= ' where ' . $query; } if ($groupQuery) { if (!$query) { $sql .= ' where true '; } $sql .= ' group by ' . $groupQuery; } if ($orderQuery) { if (!$query && !$groupQuery) { $sql .= ' where true '; } $sql .= ' order by ' . $orderQuery; } if ($this->fetchSize > 0) { $sql .= ' limit ' . $this->firstResult . ',' . $this->fetchSize; } $this->parameters = CriteriaQuery::$parameters; CriteriaQuery::$parameters = array(); $returnParameters = $this->parameters; $this->sqlString = $sql; return $this->sqlString; }
/** * 取查询结果集 * @param unknown_type $sql * @param array $binds * @return multitype: */ public function getRows($sql, array $binds = array()) { if (Configuration::$SHOW_SQL) { Log::writeMsg(Log::NOTICE, CriteriaQuery::getDumpSQL($sql, $binds)); } $sth = $this->prepare($sql); self::bindValue($sth, $binds); $this->execute($sth); $this->_lastErrorInfo = $sth->errorInfo(); $out = $sth->fetchAll(); $sth->closeCursor(); return $out; }