dbsimple.php

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

PHP
410
字号
        return $nextId;    } // end of function    /**    *   removes the given node    *    *   @version  2001/10/09    *   @access     public    *   @author   Wolfram Kriesing <wolfram@kriesing.de>    *   @param    mixed   $id   the id of the node to be removed, or an array of id's to be removed    *   @return   boolean true on success    */    function remove( $id )    {        // if the one to remove has children, get their id's to remove them too        if( $this->hasChildren($id) )            $id = $this->walk( array('_remove',$this) , $id , 'array' );        $idColumnName = 'id';        $map = $this->getOption('columnNameMaps');        if( isset($map['id']) )                     // if there are maps given        {            $idColumnName = $map['id'];        }        $whereClause = "WHERE $idColumnName=$id";        if( is_array($id) )        {            $whereClause = "WHERE $idColumnName in (".implode( ',' , $id ).')';        }        $query = "DELETE FROM {$this->table} $whereClause";//print("<br>".$query);        if( DB::isError( $res = $this->dbh->query( $query ) ) )        {// TODO raise PEAR error            printf("ERROR - Tree::remove - %s - %s<br>",DB::errormessage($res),$query);            return false;        }// TODO if remove succeeded set prevId of the following element properly        return true;    } // end of function    /**    *   move an entry under a given parent or behind a given entry    *    *   @version    2001/10/10    *   @access     public    *   @author     Wolfram Kriesing <wolfram@kriesing.de>    *   @param      integer $idToMove   the id of the element that shall be moved    *   @param      integer $newParentId    the id of the element which will be the new parent    *   @param      integer $newPrevId      if prevId is given the element with the id idToMove    *                                       shall be moved _behind_ the element with id=prevId    *                                       if it is 0 it will be put at the beginning    *                                       if no prevId is in the DB it can be 0 too and won't bother    *                                       since it is not written in the DB anyway    *   @return     boolean     true for success    */    function move( $idToMove , $newParentId , $newPrevId=0 )    {        $idColumnName = 'id';        $parentIdColumnName = 'parentId';        $map = $this->getOption('columnNameMaps');        if( isset($map['id']) )            $idColumnName = $map['id'];        if( isset($map['parentId']) )            $parentIdColumnName = $map['parentId'];// FIXXME todo: previous stuff        // set the parent in the DB        $query = "UPDATE $this->table SET $parentIdColumnName=$newParentId WHERE $idColumnName=$idToMove";//print($query);        if( DB::isError( $res = $this->dbh->query( $query ) ) )        {// TODO raise PEAR error            printf("ERROR - Tree::move - %s - %s<br>",DB::errormessage($res),$query);            return false;        }// FIXXME update the prevId's of the elements where the element was moved away from and moved in        return true;    } // end of function    /**    *   update an element in the DB    *    *   @version    2002/01/17    *   @access     public    *   @author     Wolfram Kriesing <wolfram@kriesing.de>    *   @param      array   $newData    all the new data, the key 'id' is used to    *                                   build the 'WHERE id=' clause and all the other    *                                   elements are the data to fill in the DB    *   @return     boolean true for success    */    function update( $id , $newData )    {// FIXXME check $this->dbh->tableInfo to see if all the columns that shall be updated// really exist, this will also extract nextId etc. if given before writing it in the DB// in case they dont exist in the DB        $setData = array();        foreach( $newData as $key=>$value )       // quote the values, as needed for the insert        {            $setData[] = $this->_getColName($key).'='.$this->dbh->quote($value);        }        $query = sprintf(   'UPDATE %s SET %s WHERE %s=%s',                            $this->table,                            implode( ',' , $setData ),                            $this->_getColName('id'),                            $id                        );        if( DB::isError( $res=$this->dbh->query($query) ) )        {// FIXXME raise PEAR error            printf("ERROR - Tree::update - %s - %s<br>",DB::errormessage($res),$query);            return false;        }        return true;    } // end of function    /**    *    *    *   @access     private    *   @version    2002/03/02    *   @author     Wolfram Kriesing <wolfram@kriesing.de>    *   @param    *   @return    */    function _throwError( $msg , $line , $mode=null )    {        return new Tree_Error( $msg , $line , __FILE__ , $mode , $this->db->last_query );    }    /**    *   prepare multiple results    *    *   @see        _prepareResult()    *   @access     private    *   @version    2002/03/03    *   @author     Wolfram Kriesing <wolfram@kriesing.de>    *   @param    *   @return    */    function _prepareResults( $results )    {        $newResults = array();        foreach( $results as $aResult )            $newResults[] = $this->_prepareResult($aResult);        return $newResults;    }    /**    *   map back the index names to get what is expected    *    *   @access     private    *   @version    2002/03/03    *   @author     Wolfram Kriesing <wolfram@kriesing.de>    *   @param    *   @return    */    function _prepareResult( $result )    {        $map = $this->getOption('columnNameMaps');        if( $map )        foreach( $map as $key=>$columnName )        {            $result[$key] = $result[$columnName];            unset($result[$columnName]);        }        return $result;    }    /**    *   this method retreives the real column name, as used in the DB    *   since the internal names are fixed, to be portable between different    *   DB-column namings, we map the internal name to the real column name here    *    *   @access     private    *   @version    2002/03/02    *   @author     Wolfram Kriesing <wolfram@kriesing.de>    *   @param    *   @return    */    function _getColName( $internalName )    {        if( $map = $this->getOption( 'columnNameMaps' ) )        {            if( isset($map[$internalName]) )                return $map[$internalName];        }        return $internalName;    }} // end of class?>

⌨️ 快捷键说明

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