/** * Render LIMIT OFFSET clause * * @param string $sql SQL query * @return string */ protected function _renderLimitoffset($sql) { $count = 0; $offset = 0; if (!empty($this->_parts[self::LIMIT_OFFSET])) { $offset = (int) $this->_parts[self::LIMIT_OFFSET]; $count = PHP_INT_MAX; } if (!empty($this->_parts[self::LIMIT_COUNT])) { $count = (int) $this->_parts[self::LIMIT_COUNT]; } /* * Add limits clause */ if ($count > 0) { $sql = trim($this->_adapter->limit($sql, $count, $offset)); } return $sql; }
/** * Special handling for PDO query(). * All bind parameter names must begin with ':' * * @param string|\libDb\Select $sql The SQL statement with placeholders. * @param array $bind An array of data to bind to the placeholders. * @return Pdo * @throws \libDb\Statement\Exception To re-throw PDOException. */ public function query($sql, $bind = array()) { if (empty($bind) && $sql instanceof \libDb\Select) { $bind = $sql->getBind(); } if (is_array($bind)) { foreach ($bind as $name => $value) { if (!is_int($name) && !preg_match('/^:/', $name)) { $newName = ":{$name}"; unset($bind[$name]); $bind[$newName] = $value; } } } try { return parent::query($sql, $bind); } catch (\PDOException $e) { throw new \libDb\Statement\Exception($e->getMessage(), $e->getCode(), $e); } }
/** * Support method for fetching rows. * * @param Select $select query options. * @return array An array containing the row results in FETCH_ASSOC mode. */ protected function _fetch(Select $select) { $stmt = $this->_db->query($select); $data = $stmt->fetchAll(Db::FETCH_ASSOC); return $data; }