query.php

来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· PHP 代码 · 共 1,920 行 · 第 1/5 页

PHP
1,920
字号
     * remove the datasets with the given ids     *     * @version    2002/04/24     * @access     public     * @author     Wolfram Kriesing <wk@visionp.de>     * @param      array   the ids to remove     * @return     */    function removeMultiple($ids, $colName='')    {        if (empty($colName)) {            $colName = $this->primaryCol;        }        $ids = $this->_quoteArray($ids);        $query = sprintf(   'DELETE FROM %s WHERE %s IN (%s)',                            $this->table,                            $colName,                            implode(',', $ids)                        );        return $this->execute($query, 'query') ? true : false;    }    // }}}    // {{{ removePrimary()    /**     * removes a member from the DB and calls the remove methods of the given objects     * so all rows in another table that refer to this table are erased too     *     * @version    2002/04/08     * @access     public     * @author     Wolfram Kriesing <wk@visionp.de>     * @param      integer the value of the primary key     * @param      string  the column name of the tables with the foreign keys     * @param      object  just for convinience, so nobody forgets to call this method     *                       with at least one object as a parameter     * @return     boolean     */    function removePrimary($id, $colName, $atLeastOneObject)    {        $argCounter = 2;    // we have 2 parameters that need to be given at least        // func_get_arg returns false and a warning if there are no more parameters, so        // we suppress the warning and check for false        while ($object = @func_get_arg($argCounter++)) {//FIXXXME let $object also simply be a table name            if (!$object->remove($id, $colName)) {//FIXXXME do this better                $this->_errorSet("Error removing '$colName=$id' from table {$object->table}.");               return false;            }        }        return ($this->remove($id) ? true : false);    }    // }}}    // {{{ setLimit()    /**     * @param integer $from     * @param integer $count     */    function setLimit($from=0, $count=0)    {        if ($from==0 && $count==0) {            $this->_limit = array();        } else {            $this->_limit = array($from, $count);        }    }    // }}}    // {{{ getLimit()    /**     * @return array     */    function getLimit()    {        return $this->_limit;    }    // }}}    // {{{ setWhere()    /**     * sets the where condition which is used for the current instance     *     * @version    2002/04/16     * @access     public     * @author     Wolfram Kriesing <wk@visionp.de>     * @param      string  the where condition, this can be complete like 'X=7 AND Y=8'     */    function setWhere($whereCondition='')    {        $this->_where = $whereCondition;//FIXXME parse the where condition and replace ambigious column names, such as "name='Deutschland'" with "country.name='Deutschland'"// then the users dont have to write that explicitly and can use the same name as in the setOrder i.e. setOrder('name,_net_name,_netPrefix_prefix');    }    // }}}    // {{{ getWhere()    /**     * gets the where condition which is used for the current instance     *     * @version    2002/04/22     * @access     public     * @author     Wolfram Kriesing <wk@visionp.de>     * @return     string  the where condition, this can be complete like 'X=7 AND Y=8'     */    function getWhere()    {        return $this->_where;    }    // }}}    // {{{ addWhere()    /**     * only adds a string to the where clause     *     * @version    2002/07/22     * @access     public     * @author     Wolfram Kriesing <wk@visionp.de>     * @param      string  the where clause to add to the existing one     * @param      string  the condition for how to concatenate the new where clause     *                       to the existing one     */    function addWhere($where, $condition='AND')    {        if ($this->getWhere()) {            $where = $this->getWhere().' '.$condition.' '.$where;        }        $this->setWhere($where);    }    // }}}    // {{{ addWhereSearch()    /**     * add a where-like clause which works like a search for the given string     * i.e. calling it like this:     *     $this->addWhereSearch('name', 'otto hans')     * produces a where clause like this one     *     LOWER(name) LIKE "%otto%hans%"     * so the search finds the given string     *     * @version    2002/08/14     * @access     public     * @author     Wolfram Kriesing <wk@visionp.de>     * @param      string  the column to search in for     * @param      string  the string to search for     */    function addWhereSearch($column, $string, $condition='AND')    {        // if the column doesn't contain a tablename use the current table name        // in case it is a defined column to prevent ambiguous rows        if (strpos($column, '.') === false) {            $meta = $this->metadata();            if (isset($meta[$column])) {                $column = $this->table.".$column";            }        }        $string = $this->db->quote('%'.str_replace(' ', '%', strtolower($string)).'%');        $this->addWhere("LOWER($column) LIKE $string", $condition);    }    // }}}    // {{{ setOrder()    /**     * sets the order condition which is used for the current instance     *     * @version    2002/05/16     * @access     public     * @author     Wolfram Kriesing <wk@visionp.de>     * @param      string  the where condition, this can be complete like 'X=7 AND Y=8'     * @param      boolean sorting order (TRUE => ASC, FALSE => DESC)     */    function setOrder($orderCondition='', $desc=false)    {        $this->_order = $orderCondition .($desc ? ' DESC' : '');    }    // }}}    // {{{ addOrder()    /**     * Add a order parameter to the query.     *     * @version    2003/05/28     * @access     public     * @author     Wolfram Kriesing <wk@visionp.de>     * @param      string  the where condition, this can be complete like 'X=7 AND Y=8'     * @param      boolean sorting order (TRUE => ASC, FALSE => DESC)     */    function addOrder($orderCondition='', $desc=false)    {        $order = $orderCondition .($desc ? ' DESC' : '');        if ($this->_order) {            $this->_order = $this->_order.','.$order;        } else {            $this->_order = $order;        }    }    // }}}    // {{{ getOrder()    /**     * gets the order condition which is used for the current instance     *     * @version    2002/05/16     * @access     public     * @author     Wolfram Kriesing <wk@visionp.de>     * @return     string  the order condition, this can be complete like 'ID,TIMESTAMP DESC'     */    function getOrder()    {        return $this->_order;    }    // }}}    // {{{ setHaving()    /**     * sets the having definition     *     * @version    2003/06/05     * @access     public     * @author     Johannes Schaefer <johnschaefer@gmx.de>     * @param      string  the having definition     */    function setHaving($having='')    {        $this->_having = $having;    }    // }}}    // {{{ getHaving()    /**     * gets the having definition which is used for the current instance     *     * @version    2003/06/05     * @access     public     * @author     Johannes Schaefer <johnschaefer@gmx.de>     * @return     string  the having definition     */    function getHaving()    {        return $this->_having;    }    // }}}    // {{{ addHaving()    /**     * Extend the current having clause. This is very useful, when you are building     * this clause from different places and don't want to overwrite the currently     * set having clause, but extend it.     *     * @param string this is a having clause, i.e. 'column' or 'table.column' or 'MAX(column)'     * @param string the connection string, which usually stays the default, which is ',' (a comma)     */    function addHaving($what='*', $connectString=' AND ')    {        if ($this->_having) {            $this->_having = $this->_having.$connectString.$what;        } else {            $this->_having = $what;        }    }    // }}}    // {{{ setJoin()    /**     * sets a join-condition     *     * @version    2002/06/10     * @access     public     * @author     Wolfram Kriesing <wk@visionp.de>     * @param      mixed   either a string or an array that contains     *                       the table(s) to join on the current table     * @param      string  the where clause for the join     */    function setJoin($table=null, $where=null, $joinType='default')    {//FIXXME make it possible to pass a table name as a string like this too 'user u'// where u is the string that can be used to refer to this table in a where/order// or whatever condition// this way it will be possible to join tables with itself, like setJoin(array('user u','user u1'))// this wouldnt work yet, but for doing so we would need to change the _build methods too!!!// because they use getJoin('tables') and this simply returns all the tables in use// but don't take care of the mentioned syntax        if (is_null($table) || is_null($where)) {   // remove the join if not sufficient parameters are given            $this->_join[$joinType] = array();            return;        }/* this causes problems if we use the order-by, since it doenst know the name to order it by ... :-)        // replace the table names with the internal name used for the join        // this way we can also join one table multiple times if it will be implemented one day        $this->_join[$table] = preg_replace('/'.$table.'/','j1',$where);*/        $this->_join[$joinType][$table] = $where;    }    // }}}    // {{{ setJoin()    /**     * if you do a left join on $this->table you will get all entries     * from $this->table, also if there are no entries for them in the joined table     * if both parameters are not given the left-join will be removed     * NOTE: be sure to only use either a right or a left join     *     * @version    2002/07/22     * @access     public     * @author     Wolfram Kriesing <wk@visionp.de>     * @param      string  the table(s) to be left-joined     * @param      string  the where clause for the join     */    function setLeftJoin($table=null, $where=null)    {        $this->setJoin($table, $where, 'left');    }    // }}}    // {{{ addLeftJoin()    /**     * @param string the table to be left-joined     * @param string the where clause for the join     * @param string the join type     */    function addLeftJoin($table, $where, $type='left')    {        // init value, to prevent E_ALL-warning        if (!isset($this->_join[$type]) || !$this->_join[$type]) {            $this->_join[$type] = array();        }        $this->_join[$type][$table] = $where;    }    // }}}    // {{{ setRightJoin()    /**     * see setLeftJoin for further explaination on what a left/right join is     * NOTE: be sure to only use either a right or a left join//FIXXME check if the above sentence is necessary and if sql doesnt allow the use of both     *     * @see        setLeftJoin()     * @version    2002/09/04     * @access     public     * @author     Wolfram Kriesing <wk@visionp.de>     * @param      string  the table(s) to be right-joined     * @param      string  the where clause for the join     */    function setRightJoin($table=null, $where=null)    {        $this->setJoin($table, $where, 'right');    }    // }}}    // {{{ getJoin()    /**     * gets the join-condition     *     * @access public     * @param  string  [null|''|'table'|'tables'|'right'|'left']     * @return array   gets the join parameters     */    function getJoin($what=null)    {        // if the user requests all the join data or if the join is empty, return it        if (is_null($what) || empty($this->_join)) {            return $this->_join;

⌨️ 快捷键说明

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