⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 select.php

📁 一款可以和GOOGLE媲美的开源统计系统,运用AJAX.功能强大. 无色提示:按照需要PHP5.1以上和MySQL数据库支持。
💻 PHP
📖 第 1 页 / 共 2 页
字号:
     * rows from the right table.     *     * The $name and $cols parameters follow the same logic     * as described in the from() method.     *     * @param  array|string|Zend_Db_Expr $name The table name.     * @param  string $cond Join on this condition.     * @param  array|string $cols The columns to select from the joined table.     * @param  string $schema The database name to specify, if any.     * @return Zend_Db_Select This Zend_Db_Select object.     */    public function joinInner($name, $cond, $cols = '*', $schema = null)    {        return $this->_join(self::INNER_JOIN, $name, $cond, $cols, $schema);    }    /**     * Add a LEFT OUTER JOIN table and colums to the query     * All rows from the left operand table are included,     * matching rows from the right operand table included,     * and the columns from the right operand table are filled     * with NULLs if no row exists matching the left table.     *     * The $name and $cols parameters follow the same logic     * as described in the from() method.     *     * @param  array|string|Zend_Db_Expr $name The table name.     * @param  string $cond Join on this condition.     * @param  array|string $cols The columns to select from the joined table.     * @param  string $schema The database name to specify, if any.     * @return Zend_Db_Select This Zend_Db_Select object.     */    public function joinLeft($name, $cond, $cols = '*', $schema = null)    {        return $this->_join(self::LEFT_JOIN, $name, $cond, $cols, $schema);    }    /**     * Add a RIGHT OUTER JOIN table and colums to the query.     * Right outer join is the complement of left outer join.     * All rows from the right operand table are included,     * matching rows from the left operand table included,     * and the columns from the left operand table are filled     * with NULLs if no row exists matching the right table.     *     * The $name and $cols parameters follow the same logic     * as described in the from() method.     *     * @param  array|string|Zend_Db_Expr $name The table name.     * @param  string $cond Join on this condition.     * @param  array|string $cols The columns to select from the joined table.     * @param  string $schema The database name to specify, if any.     * @return Zend_Db_Select This Zend_Db_Select object.     */    public function joinRight($name, $cond, $cols = '*', $schema = null)    {        return $this->_join(self::RIGHT_JOIN, $name, $cond, $cols, $schema);    }    /**     * Add a FULL OUTER JOIN table and colums to the query.     * A full outer join is like combining a left outer join     * and a right outer join.  All rows from both tables are     * included, paired with each other on the same row of the     * result set if they satisfy the join condition, and otherwise     * paired with NULLs in place of columns from the other table.     *     * The $name and $cols parameters follow the same logic     * as described in the from() method.     *     * @param  array|string|Zend_Db_Expr $name The table name.     * @param  string $cond Join on this condition.     * @param  array|string $cols The columns to select from the joined table.     * @param  string $schema The database name to specify, if any.     * @return Zend_Db_Select This Zend_Db_Select object.     */    public function joinFull($name, $cond, $cols = '*', $schema = null)    {        return $this->_join(self::FULL_JOIN, $name, $cond, $cols, $schema);    }    /**     * Add a CROSS JOIN table and colums to the query.     * A cross join is a cartesian product; there is no join condition.     *     * The $name and $cols parameters follow the same logic     * as described in the from() method.     *     * @param  array|string|Zend_Db_Expr $name The table name.     * @param  array|string $cols The columns to select from the joined table.     * @param  string $schema The database name to specify, if any.     * @return Zend_Db_Select This Zend_Db_Select object.     */    public function joinCross($name, $cols = '*', $schema = null)    {        return $this->_join(self::CROSS_JOIN, $name, null, $cols, $schema);    }    /**     * Add a NATURAL JOIN table and colums to the query.     * A natural join assumes an equi-join across any column(s)     * that appear with the same name in both tables.     * Only natural inner joins are supported by this API,     * even though SQL permits natural outer joins as well.     *     * The $name and $cols parameters follow the same logic     * as described in the from() method.     *     * @param  array|string|Zend_Db_Expr $name The table name.     * @param  array|string $cols The columns to select from the joined table.     * @param  string $schema The database name to specify, if any.     * @return Zend_Db_Select This Zend_Db_Select object.     */    public function joinNatural($name, $cols = '*', $schema = null)    {        return $this->_join(self::NATURAL_JOIN, $name, null, $cols, $schema);    }    /**     * Adds a WHERE condition to the query by AND.     *     * If a value is passed as the second param, it will be quoted     * and replaced into the condition wherever a question-mark     * appears. Array values are quoted and comma-separated.     *     * <code>     * // simplest but non-secure     * $select->where("id = $id");     *     * // secure (ID is quoted but matched anyway)     * $select->where('id = ?', $id);     *     * // alternatively, with named binding     * $select->where('id = :id');     * </code>     *     * Note that it is more correct to use named bindings in your     * queries for values other than strings. When you use named     * bindings, don't forget to pass the values when actually     * making a query:     *     * <code>     * $db->fetchAll($select, array('id' => 5));     * </code>     *     * @param string $cond The WHERE condition.     * @param string $val A single value to quote into the condition.     * @return Zend_Db_Select This Zend_Db_Select object.     */    public function where($cond)    {        if (func_num_args() > 1) {            $val = func_get_arg(1);            $cond = $this->_adapter->quoteInto($cond, $val);        }        if ($this->_parts[self::WHERE]) {            $this->_parts[self::WHERE][] = "AND ($cond)";        } else {            $this->_parts[self::WHERE][] = "($cond)";        }        return $this;    }    /**     * Adds a WHERE condition to the query by OR.     *     * Otherwise identical to where().     *     * @param string $cond The WHERE condition.     * @param string $val A value to quote into the condition.     * @return Zend_Db_Select This Zend_Db_Select object.     *     * @see where()     */    public function orWhere($cond)    {        if (func_num_args() > 1) {            $val = func_get_arg(1);            $cond = $this->_adapter->quoteInto($cond, $val);        }        if ($this->_parts[self::WHERE]) {            $this->_parts[self::WHERE][] = "OR ($cond)";        } else {            $this->_parts[self::WHERE][] = "($cond)";        }        return $this;    }    /**     * Adds grouping to the query.     *     * @param  array|string $spec The column(s) to group by.     * @return Zend_Db_Select This Zend_Db_Select object.     */    public function group($spec)    {        if (!is_array($spec)) {            $spec = array($spec);        }        foreach ($spec as $val) {            if (preg_match('/\(.*\)/', (string) $val)) {                $val = new Zend_Db_Expr($val);            }            $this->_parts[self::GROUP][] = $val;        }        return $this;    }    /**     * Adds a HAVING condition to the query by AND.     *     * If a value is passed as the second param, it will be quoted     * and replaced into the condition wherever a question-mark     * appears. See {@link where()} for an example     *     * @param string $cond The HAVING condition.     * @param string|Zend_Db_Expr $val A single value to quote into the condition.     * @return Zend_Db_Select This Zend_Db_Select object.     */    public function having($cond)    {        if (func_num_args() > 1) {            $val = func_get_arg(1);            $cond = $this->_adapter->quoteInto($cond, $val);        }        if ($this->_parts[self::HAVING]) {            $this->_parts[self::HAVING][] = "AND ($cond)";        } else {            $this->_parts[self::HAVING][] = "($cond)";        }        return $this;    }    /**     * Adds a HAVING condition to the query by OR.     *     * Otherwise identical to orHaving().     *     * @param string $cond The HAVING condition.     * @param string $val A single value to quote into the condition.     * @return Zend_Db_Select This Zend_Db_Select object.     *     * @see having()     */    public function orHaving($cond)    {        if (func_num_args() > 1) {            $val = func_get_arg(1);            $cond = $this->_adapter->quoteInto($cond, $val);        }        if ($this->_parts[self::HAVING]) {            $this->_parts[self::HAVING][] = "OR ($cond)";        } else {            $this->_parts[self::HAVING][] = "($cond)";        }        return $this;    }    /**     * Adds a row order to the query.     *     * @param mixed $spec The column(s) and direction to order by.     * @return Zend_Db_Select This Zend_Db_Select object.     */    public function order($spec)    {        if (!is_array($spec)) {            $spec = array($spec);        }        // force 'ASC' or 'DESC' on each order spec, default is ASC.        foreach ($spec as $val) {            if ($val instanceof Zend_Db_Expr) {                $expr = $val->__toString();                if (empty($expr)) {                    continue;                }                $this->_parts[self::ORDER][] = $val;            } else {                if (empty($val)) {                    continue;                }                $direction = 'ASC';                if (preg_match('/(.*)\s+(ASC|DESC)\s*$/i', $val, $matches)) {                    $val = trim($matches[1]);                    $direction = $matches[2];                }                if (preg_match('/\(.*\)/', $val)) {                    $val = new Zend_Db_Expr($val);                }                $this->_parts[self::ORDER][] = array($val, $direction);            }        }        return $this;    }    /**     * Sets a limit count and offset to the query.     *     * @param int $count OPTIONAL The number of rows to return.     * @param int $offset OPTIONAL Start returning after this many rows.     * @return Zend_Db_Select This Zend_Db_Select object.     */    public function limit($count = null, $offset = null)    {        $this->_parts[self::LIMIT_COUNT]  = (int) $count;        $this->_parts[self::LIMIT_OFFSET] = (int) $offset;        return $this;    }    /**     * Sets the limit and count by page number.     *     * @param int $page Limit results to this page number.     * @param int $rowCount Use this many rows per page.     * @return Zend_Db_Select This Zend_Db_Select object.     */    public function limitPage($page, $rowCount)    {        $page     = ($page > 0)     ? $page     : 1;        $rowCount = ($rowCount > 0) ? $rowCount : 1;        $this->_parts[self::LIMIT_COUNT]  = (int) $rowCount;        $this->_parts[self::LIMIT_OFFSET] = (int) $rowCount * ($page - 1);        return $this;    }    /**     * Adds to the internal table-to-column mapping array.     *     * @param  string $tbl The table/join the columns come from.     * @param  array|string $cols The list of columns; preferably as     * an array, but possibly as a string containing one column.     * @return void     */    protected function _tableCols($correlationName, $cols)    {        if (!is_array($cols)) {            $cols = array($cols);        }        if ($correlationName == null) {            $correlationName = '';        }        foreach ($cols as $alias => $col) {            $currentCorrelationName = $correlationName;            if (is_string($col)) {                // Check for a column matching "<column> AS <alias>" and extract the alias name                if (preg_match('/^(.+)\s+AS\s+(.+)$/i', $col, $m)) {                    $col = $m[1];                    $alias = $m[2];                }                // Check for columns that look like functions and convert to Zend_Db_Expr                if (preg_match('/\(.*\)/', $col)) {                    $col = new Zend_Db_Expr($col);                } elseif (preg_match('/(.+)\.(.+)/', $col, $m)) {                    $currentCorrelationName = $m[1];                    $col = $m[2];                }            }            $this->_parts[self::COLUMNS][] = array($currentCorrelationName, $col, is_string($alias) ? $alias : null);        }    }    /**     * Get part of the structured information for the currect query.     *     * @param string $part     * @return mixed     * @throws Zend_Db_Select_Exception     */    public function getPart($part)    {        $part = strtolower($part);        if (!array_key_exists($part, $this->_parts)) {            /**             * @see Zend_Db_Select_Exception             */            require_once 'Zend/Db/Select/Exception.php';            throw new Zend_Db_Select_Exception("Invalid Select part '$part'");        }        return $this->_parts[ $part ];    }    /**     * @param integer $fetchMode OPTIONAL     * @return PDO_Statement|Zend_Db_Statement     */    public function query($fetchMode = null)    {        $stmt = $this->_adapter->query($this);        if ($fetchMode == null) {            $fetchMode = $this->_adapter->getFetchMode();        }        $stmt->setFetchMode($fetchMode);        return $stmt;    }    /**     * Clear parts of the Select object, or an individual part.     *     * @param string $part OPTIONAL     * @return Zend_Db_Select     */    public function reset($part = null)    {        if ($part == null) {            $this->_parts = self::$_partsInit;        } else if (array_key_exists($part, self::$_partsInit)) {            $this->_parts[$part] = self::$_partsInit[$part];        }        return $this;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -