听说高手都有自己的mysql库?能不能发出来看看?

解决方案 »

  1.   

    ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd
      

  2.   

    我平时做单用的.<?
    /**
    * 数据库类.

    * 封装常见的数据库操作,包括分页处理.

    * @author  徐兴
    * @package lib
    * @version v1.0
    * @copyright .
    *
    */class db {
    /**
     * 可以选择mysql oracle sql
     * @access  public
     * @var   数据库类型 
     */
    public $dbtype='mysql';   

    /**
     * 默认的数据库连接所用的用户名.
     * @access  public
     * @var   数据库用户名  
     */
    public $user='';  

    /**
     * 默认的数据库连接所用的用户密码
     * @access  public
     * @var   数据库密码 
     */
    public $pass='';           
    /**
     * 数据库主机地址,本机默认写localhost
     * @access  public
     * @var   数据库主机地址 
     */
    public $host='';    /**
     * 指定的不当前操作的数据库
     * @access  public
     * @var   数据库,指定的库
     */
    public $database='';   /**
     * 数据库的连接句柄
     * @access  public
     * @var   句柄
     */
    public $handle;        

    /**
     * 记录集
     * @access  public
     * @var   记录集
     */
    public $rs = array();      
    /**
     * 最后一次记录集
     * @access  public
     * @var   最后一次记录集
     */
    public $last_rs = '';     

    /**
     * 分页记录中一页数据的行数
     * @access  public
     * @var   分页记录中一页数据的行数
     */

    public $rows_num=0;        //记录行数
    public $page=0;            //页
    public $pages_num=0;       //页数
    public $rows_per_page=0;   //每页记录行数
    public $rows_offset=0;     //行偏移,使用较少
    public $params='';          //参数
    public $show_page_num=0;   //页式2时示页(为)
    public $func_ary = array(  
    'farray'       => 'mysql_fetch_array',
    'fnum'         => 'mysql_fetch_row',
    'ffield'       => 'mysql_fetch_assoc',
    'fobject'      => 'mysql_fetch_object',
    );
    /**
     * 指定数据库类型,是mysql 还是sql,还是orecle.
     * @param 数据库的类型 $type
     * @return bool
     */
    function __construct( $type='mysql' ) {
    if( $type!='' ) $this->dbtype = $type;
    if( !$this->func_ary[$this->dbtype] ) {
    return false;
    }else {
    return true;
    }
    }
      /**
       * *创建一个数据库的连接.
       *
       * @param string $host -主机名称
       * @param string $user -数据库用户名
       * @param 数据库用户密码 $pass
       * @return 数据库句柄.handle 
       */
    function conn( $host = '192.168.100.137' , $user = 'xuxing' , $pass = '******' ) {
    if( gettype( $host ) == 'resource' ) {
    $this->handle = $host;
    }else {
    if( $host != '' ) $this->host = $host;
    if( $user != '')  $this->user = $user;
    if( $pass != '')  $this->pass = $pass;
    $this->handle = mysql_connect( $this->host , $this->user , $this->pass , false , MYSQL_CLIENT_COMPRESS ) or die( "系统忙,请稍厚" );
    $this->query( "SET NAMES utf8") or die( "set names utf-8 失败" );
    return $this->handle;
    }
    } /**
     * *关闭数据库连接.
     *
     */
    function close() {
    @mysql_close($this->handle);
    } /**
     * *指定所选的数据库.
     *
     * @param 指定的当前操作的数据库名. $database
     */
    function setdb( $database = 'pm' ) {
    if( $database != '' ) $this->database = $database;
    @mysql_select_db( $this->database , $this->handle );
    } /**
    * 执行一个sql语句.
    * @param 查询语句,支持单个sql和数组模式.。 $sql
    * @return 
        */              
    function query( $sql ) {
    if( is_array( $sql ) ) {

    for($i=0; $i<sizeof($sql); $i++) {
    $tmp = @mysql_query($sql[$i],$this->handle);
    }
    return $tmp;
    }else {
    return @mysql_query($sql,$this->handle);
    }
    } /**
    * 取出最新插入数据库的id号.
    * @return  int 
    */  
    function insid() {
    return @mysql_insert_id($this->handle);
    } /**
    * 获取影响的行数.
    */  
    function affrow() {
    return @mysql_affected_rows($this->handle);
    } /*  */
    function err() {
    return array(@mysql_errno(), @mysql_error($this->handle));
    } /* 已记录集方式得到记录本 */
    function rs( $sql = '' , $rs_name = '' ) {
    if( $rs_name == '' && $this->last_rs == '') {
    $rs_name='rs';
    }elseif( $rs_name == '' ) {
    $rs_name = $this->last_rs;
    }
    $sql_tmp = is_array( $sql )? $sql [ sizeof( $sql ) ] : $sql;
    if( $sql_tmp != '' && $this->result[ $rs_name ][ 0 ] != $sql ){
    $tmp = $this->query( $sql );
    $this->result[ $rs_name ] = array( $sql_tmp,$tmp );
    $this->last_rs = $rs_name;
    }
    return $this->result[ $rs_name ][1];
    } /* 以数组方式取得 */
    function rn( $sql='' , $type = 'num' , $rs_name = '',$num = 1) {
    if( !$type ) $type = 'num';
    if( !in_array( $type , array( 'num' , 'field' , 'array' , 'object' ))) return false;
          if( $num == 1 ) {
    return @$this->func_ary[ 'f'. $type ]( $this->rs( $sql , $rs_name));
    }elseif( $num == 'all' ) {
    while( $tmp[] = @$this->func_ary[ 'f'.$type ]( $this->rs( $sql , $rs_name ))) {
    }
    }elseif( is_int( $num )) {
    for( $i = 0 ;  $i < $num ; $i++ ) {
    $tmp1 = @$this->func_ary[ 'f'.$type ]( $this->rs( $sql , $rs_name ) );
    if( $tmp1 === false ) {
    break;
    }else {
    $tmp[] = $tmp1;
    }
    }
    }else {
    return false;
    }
    return $tmp;
    } /**
     *  得到单值 
     */
    function val( $sql ) {
    if( DEBUG == "1" ){echo $sql."<hr/>";}

    $tmp = mysql_fetch_row($this->query($sql));
    if( is_null($tmp)) {
    echo "没有你要取得值";
    }
    return $tmp[0];
    }


    /**
     * 通过表中的一个字段的值来取得另个字段,或者是一组数据的方法.
     * @param  值的编号. $id
     * @param  需要取得的数据的字段名. $attrName
     * */
    function getValue($id,$attrName,$table,$condKey)
    {
    $table = $table;
    $cond = "where $condKey = '$id'";
    $sql = "select $attrName from $table $cond";

        if(DEBUG == "1")
    {
    echo "getValue".$sql."<hr/>";
    }
     
    $value = $this->val($sql);
    if(DEBUG == "1")
    {
    echo "你所求的值为 $value    |";
    }
     return $value;
    }



    /**
     *  得到行数 
     */
    function num($sql='',$rs_name='rs') {
    return @mysql_num_rows($this->rs($sql,$rs_name));
    }
    /**
     *  清空记录集 
     */
    function clean($rs_name) {
    if(is_array($rs_name)) {
    foreach($rs_name as $val) {
    @mysql_free_result($this->result[$rs_name][1]);
    unset($this->result[$val]);
    }
    }else {
    @mysql_free_result($this->result[$rs_name][1]);
    unset($this->result[$rs_name]);
    }
    }
    /**
     *  重设记录集 
     */
    function reset ($rs_name) {
    if(is_array($rs_name)) {
    foreach($rs_name as $val) {
    @mysql_data_seek($this->result[$val][1],0);
    }
    }else {
    @mysql_data_seek($this->result[$rs_name][1],0);
    }
    }
      

  3.   

    接上贴 /**
     *  指定分页 
     */
    function pnum($page,$rows_num,$rows_per_page=20,$offset=0) {
    if($rows_num)      $this->rows_num      = $rows_num;
    if($rows_per_page) $this->rows_per_page = $rows_per_page;
    if($offset)        $this->offset        = $offset;
    if(!$page)         $page =1;
    $this->page = $page;
    $this->pages_num = ceil(($this->rows_num-$this->offset)/$this->rows_per_page);
    Return $this->pages_num;
    } /* 进行分页处理 */
    function page($sql,$rs_name='') {
    switch($this->dbtype) {
    case 'mysql':
    $sql = $sql." limit ".(($this->page-1)*$this->rows_per_page+$this->offset).", ".$this->rows_per_page;


    return $this->rs($sql,$rs_name);
    break;
    }
    }
    /**
     * * 输出分页条.
     *
     * @param 分页的格式类型 $style
     * @param 显示多少个分页标签. $show_page_num
     */
    function nav(  $style='nav1',  $show_page_num=15 ) {
    switch( $style ) {
    /* 分页1:  页 | 页 | 页 | 末页 */
    case 'nav1':
    if ( $this->page > 1 ) {
    $nav .= '<a href="?page=1&'. $this->params .'" class="page_linked">页</a> | ';
    $nav .= '<a href="?page='. ($this->page-1) .'&'. $this->params .'"  class="page_linked">页</a> | ';
    }else {
    $nav .= '<span class="page_unlink">页</span> | ';
    $nav .= '<span class="page_unlink">页</span> | ';
    }
    if ($this->page < $this->pages_num ) {
    $nav .= '<a href="?page='.( $this->page+1 ).'&'. $this->params .'" class="page_linked">页</a> | ';
    $nav .= '<a href="?page='. $this->pages_num .'&'. $this->params .'" class="page_linked">末页</a>';
    }else {
    $nav .= '<span class="page_unlink">页</span> | ';
    $nav .= '<span class="page_unlink">末页</span>';
    }
    break;
    /* 分页模式2:   1 2 3 4 5 6 7 8 9 页*/
    case 'nav2':
    for( $i=1 ; $i <= $this->pages_num; $i++ ) {
    if( $i == $this->page ) {
    $nav .= " <font style='font-size:12pt' face='Verdana'><b> $i </b></font> ";
    }else {
    $nav .= " <a href=?page=$i&". $this->params ."><font style='font-size:9pt;' face='Verdana'>$i</font></a> ";
    }
    }
    $nav = " $nav 页";
    break;
    case 'nav3':
    echo "
    <style>
    .page, .page_select
    {
    width:25px;
    text-decoration: none;
    text-align: center;
    border: 1px solid #092FB3;
    font-size:9pt;
    float:left;
    line-height:25px;
    margin-right:2px;
    }
    .page{
    color:#092FB3;
    background-color: #EEF8FF;
    display:block;
    }
    .page_select
    {
    color:#EEF8FF;
    background-color: #092FB3;
    font-weight: bolder;
    }
    .a_nav
    {
    color:#092FB3;
    text-decoration: none;
    text-align: center;
    font-size:9pt;
    line-height:25px;
    float:left;
    }
    </style>
    ";
    if($show_page_num) $this->show_page_num = $show_page_num;
    $page          = $this->page;
    $show_page_num = $this->show_page_num;
    $pages_num     = $this->pages_num;
    $param         = $this->params;
    $mid = ceil(($show_page_num+1)/2);
    $nav = '';
    if($page<=$mid ) {
    $begin = 1;
    }else if($page > $pages_num-$mid) {
    $begin = $pages_num-$show_page_num+1;
    }else {
    $begin = $page-$mid+1;
    }

    /**
     * patch for param; 保留原有的查询条件.
     * */
    $param = $_SERVER["QUERY_STRING"];
    $pattern = "/&page=(\d)/i";
    $replacement = "";
    $param =  preg_replace($pattern, $replacement, $param);

    if($begin<0) $begin = 1;
    if($begin!=1) $nav .= " <a href='?$param&page=1' title='1页' class ='a_nav'><< 首页</a>  ";
    if($page>1)   $nav .= " <a href='?$param&page=".($page-1)."' title='".($page-1)."页' class ='a_nav'><<上一页</a> ";
    $end = ($begin+$show_page_num>$pages_num)?$pages_num+1:$begin+$show_page_num;
    for($i=$begin; $i<$end; $i++) {
    $nav .=($page!=$i)?" <a href='?$param&page=$i' class = 'page'  title='{$i}页'>$i</a> ":" <span  class = 'page_select'>$i</span> ";
    }
    if($page<$pages_num)   $nav .= " <a href='?$param&page=".($page+1)."' title='".($page+1)."页' class ='a_nav'>下一页 >></a> ";
    if($end!=$pages_num+1) $nav .= "  <a href='?$param&page=$pages_num' title='{$pages_num}页' class ='a_nav'>尾页 >></a> ";
    break;

    /* 第四类分页 */
    case 'nav4':
    if($show_page_num) $this->show_page_num = $show_page_num;
    $page          = $this->page;
    $show_page_num = $this->show_page_num;
    $pages_num     = $this->pages_num;
    $param         = $this->params;
    if (!$pages_num) $pages_num =1;
    $nav = "<a href='?$param' title='1页'><font face=webdings>9</font></a> ";

    if ($page>1) {
    $nav .="<a href='?$param&page=".($page-1)."' title='".($page-1)."页'><font face=webdings>7</font></a> ";
    }else {
    $nav .= "<font face=webdings>7</font> ";
    }
    if ($page<=2||$pages_num<$show_page_num) {
    $begin=1;
    } elseif ($page>$pages_num-$show_page_num+2) {
    $begin = $pages_num-$show_page_num+1;
    }else {
    $begin = $page-2;
    }
    if ($pages_num<$show_page_num) {
    $end =$pages_num;
    }else {
    $end = $begin+$show_page_num-1;
    }

    for ($i=$begin;$i<=$end;$i++) {
    $nav .=($page!=$i)?"<a href='?$param&page=$i' title='{$i}页' class=nav> $i </a> ":"<font color='#000000'><b> <U>$i</U> </b></font> ";
    }

    if ($page<$pages_num) {
    $nav .="<a href='?$param&page=".($page+1)."' title='".($page+1)."页'><font face=webdings>8</font></a> ";
    }else {
    $nav .= "<font face=webdings>8</font> ";
    }
     $nav .="<a href='?page=$pages_num&$param' title='尾页'><font face=webdings>:</font></a>  <b><font color='#74A2DE'>".$pages_num."</font>页</b>";
    break;
    /*直转 */
    case 'listjump':
    $nav = '
     <select onchange="location.href=\'?'.$this->params.'&page=\'+this.value;">
    <script language="JavaScript">
    <!--
    for(i=1; i<='.$this->pages_num.'; i++) {
    document.write("<option value="+i+(i=='.$this->page.'?" selected":"")+">"+i+"</option>");
    }
    //-->
    </script>
    </select> 页';
    break;
    case 'inputjump':
    return "<script language='javascript'>function pagejump(){if (document.all.pagejmp.value == ''|| document.all.pagejmp.value < 0 ) {document.all.pagejmp.focus();alert('转页搿?;return false;}else{this.location.href = '?page='+document.all.pagejmp.value+'&".$this->params."'; target = '_self';}}</script>  转 <input name=pagejmp size=2 onkeydown='if(window.event.keyCode==13) pagejump();'> 页 <img src=".gd('user')."images/go1.gif align=absmiddle onclick='pagejump();' style='cursor:hand;'>";
    break;
    case 'imagejump':
    return "<script language='javascript'>function pagejump(){if (document.all.pagejmp.value == ''|| document.all.pagejmp.value < 0 ) {document.all.pagejmp.focus();alert('转页搿?;return false;}else{this.location.href = '?page='+document.all.pagejmp.value+'&".$this->params."'; target = '_self';}}</script>  转 <input name=pagejmp size=4 onkeydown='if(window.event.keyCode==13) pagejump();' style='border:1px solid #424242; height:16px;'> 页 <img src=".gd('magzine')."images/go.gif align=absmiddle onclick='pagejump();' style='cursor:hand;' width=25 height=17>";
    break;
    default:
    $nav = '';
    }
    return $nav;
    }
    }
    /**
     *   数据库初始化问题。 
     */
    function db_init() {
    global $db;
    $db = new db();
    $db->conn();
    $db->setdb("juwang");
    }
    ?>
      

  4.   

    再发一个
    <?php
    /*******************************************************************************
    数据库控制类
    默认连接MySQL数据库,如还需连接其它数据库需另行说明。
    $dbObj = new DbControl($dbConnectRoute, $dbUsername, $dbPassword, $dbName);   //定义数据库控制类
    //getObjListByAttribArray(表名, 排序方式, 需要搜索的属性(数组), 搜索的关键字, 属性的名称(数组), 属性的值(数组) , 读取信息的条数)
    list($objList, $objNumber) = $dbObj->getObjListByAttribArray($tableName, $sortKey[0], $searchKey, $searchWord, $attribName, $attribValue, $limitNumber);
    *******************************************************************************///引入外部文件
    class DbControl{
        //定义属性
        var $dbConnectRoute, $dbUsername, $dbPassword, $dbName, $dbResource;    //构造函数
        function DbControl($dbConnectRoute, $dbUsername, $dbPassword, $dbName){
            $this->dbConnectRoute = $dbConnectRoute;
            $this->dbUsername = $dbUsername;
            $this->dbPassword = $dbPassword;
            $this->dbName = $dbName;
            $this->dbResource = $this->dbConnect();
        }    //连接数据库函数 返回数据库连接句柄
        function dbConnect(){
            $dbResource = @mysql_connect($this->dbConnectRoute, $this->dbUsername, $this->dbPassword) OR die($dbConnectFailedPrompt);
            @mysql_select_db($this->dbName) OR die($dbOpenFailedPrompt);
            return $dbResource;
        }
        //关闭数据库函数
        function dbClose(){
            @mysql_close($this->dbResource);
        }    //按照ID值取得表格中的一行数据
        function getObjInfoById($tableName, $objId)
        {
            if($objId<1){$num = 0;}
            else{$num = 1;}
            $sqlString = "SELECT * FROM ".$tableName." WHERE ".$tableName."_id='".$objId."' LIMIT ".$num.";";
            $result = @mysql_query($sqlString);
            $objInfo = @mysql_fetch_object($result);
            return $objInfo;
        }

    //按照sql语句执行
    function getObjListBySql($sqlString)
        {
     
            $result = @mysql_query($sqlString);
            $numOfObjList = 0;
            while($objList[$numOfObjList] = @mysql_fetch_object($result))   //将数据表中的信息存放到数组中
            {$numOfObjList++;}
            return array($objList, $numOfObjList);    //返回一个数据信息的数组和个数    }

    /*
    //按照几个特定的属性(数组表示)读取数据库的对象信息 ,同时返回所有的数据信息
    $attribName : 属性的名称,是个数组
    $attribValue : 属性的值,是个数组
    */
    function getObjListTable($tableName, $attribName="", $attribValue="",$operator="AND")
        {
     $sqlString = "SELECT * FROM ".$tableName." WHERE ";   //第一部分语句
    if(sizeof($attribName)>0 && $attribValue[0]!='0'&&$attribValue[0]!='')
    {
    $sqlString .= "(";
    }
            for($i=0;$i<(sizeof($attribName));$i++){  //拆分属性
                if($attribValue[$i]!='0'&&$attribValue[$i]!=''&&$attribName[$i]!=""){
                    if($i==(sizeof($attribName)-1))
                        $sqlString .= $attribName[$i]."='".$attribValue[$i]."') AND ";
                    else
                        $sqlString .= $attribName[$i]."='".$attribValue[$i]."' ".$operator." ";
                }
            }
            $sqlString .= $tableName."_id<>0";      //除掉ID为0的数据
            $result = @mysql_query($sqlString);
            $numOfObjList = 0;
            while($objList[$numOfObjList] = @mysql_fetch_object($result))   //将数据表中的信息存放到数组中
            {$numOfObjList++;}
            return array($objList, $numOfObjList,$sqlString);    //返回一个数据信息的数组和个数    }


    /*根据$parent_id来查询分类读取数据库的对象信息 ,同时返回所有的数据信息
        $tableName : 表名
    $sortKey : 排序方式
        $parent_id : 默认是1查询所有类别,0,查询一级类别
        */
    function getObjListByCategories($tableName, $sortKey="", $parent_id=1)
        {
    $sqlString ="SELECT * FROM ".$tableName." WHERE ".$tableName."_id>0 ";//第一部分语句
    if($parent_id==0)$sqlString .="and ".$tableName."_parent_id=0"; //第二部分语句//如果$category等于0那么就是查询一级类别
    if($sortKey!=""){$sqlString .= " ORDER BY ".$sortKey;}       //排序方式
            $result = @mysql_query($sqlString);
            $numOfObjList = 0;
            while($objList[$numOfObjList] = @mysql_fetch_object($result))   //将数据表中的信息存放到数组中
            {$numOfObjList++;}
            return array($objList, $numOfObjList);    //返回一个数据信息的数组和个数
        }
        /*按照几个特定的属性(数组表示)读取数据库的对象信息 ,同时返回所有的数据信息
        $tableName : 表名
        $sortKey : 排序方式
        $searchKey:  需要搜索的属性,是个数组
        $searchWord: 搜索的关键字
        $attribName : 属性的名称,是个数组    $attribValue : 属性的值,是个数组
        $limitNumber : 读取信息的条数    $operator : 选择属性之间是用AND还是OR,默认为 AND
        */
            function getObjListByAttribArray($tableName, $sortKey="", $searchKey="", $searchWord="", $attribName="", $attribValue="", $limitNumber="", $limitStart="", $othercondition="", $operator="AND", $id=0)
        {
            $n = sizeof($searchKey)-1;
            $tok = strtok($searchWord," ");   //将搜索的字段按照空格拆分成一个数组


            $sqlString = "SELECT * FROM ".$tableName." WHERE ";   //第一部分语句


    if(sizeof($attribName)>0 && $attribValue[0]!='0'&&$attribValue[0]!='')
    {

    $sqlString .= "(";
    }
            for($i=0;$i<(sizeof($attribName));$i++){  //拆分属性
                if($attribValue[$i]!='0'&&$attribValue[$i]!=''&&$attribName[$i]!=""){
                    if($i==(sizeof($attribName)-1))
                        $sqlString .= $attribName[$i]."='".$attribValue[$i]."') AND ";
                    else
                        $sqlString .= $attribName[$i]."='".$attribValue[$i]."' ".$operator." ";
                }
            }
            $sqlString .= $tableName."_id<>'" . $id . "'";      //除掉ID为0的数据        while($tok){     //拆分搜索关键字            $sqlString .= "AND (";
                for($j=0;$j<$n;$j++){
                    $sqlString .= $searchKey[$j]." LIKE \"%".$tok."%\" OR ";
                }
                $sqlString .= $searchKey[$n]." LIKE \"%".$tok."%\"";
                $sqlString .= ") ";
                $tok = strtok(" ");
            }
            if($sortKey!=""){$sqlString .= " ORDER BY ".$sortKey;}       //排序方式
    if($limitStart!="" && $limitNumber!=""){$sqlString .= " LIMIT " . $limitStart . ", " . $limitNumber . ";";}
            elseif($limitNumber!=""){$sqlString .= " LIMIT ".$limitNumber.";";}      //限制信息读取的条数

            if( DEBUG == "1" ) echo $sqlString;
            $result = mysql_query($sqlString) or die("<br><br>" . $sqlString);

    $numOfObjList = 0;
            while($objList[$numOfObjList] = @mysql_fetch_object($result))   //将数据表中的信息存放到数组中
            {$numOfObjList++;}  return array($objList, $numOfObjList);    //返回一个数据信息的数组和个数    }   ?>
      

  5.   

    //读取表中最大的ID值
    /*
    $tableName : 表名
    */
    function getMaxIdFromTable($tableName)
        {
            $sqlString = "SELECT max(".$tableName."_id) AS maxId FROM ".$tableName.";";
            $result = @mysql_query($sqlString);
            while($row = @mysql_fetch_Array($result)){
               $maxId = $row["maxId"];
            }
            @mysql_query($sqlString);
            return $maxId;
        }  /*将表中的最后一行数据复制,作为新的一行数据添加到表中,同时更新指定的属性
        $tableName : 表名
        $attribName : 属性的名称 ,是个数组
        $attribValue : 属性的值 ,是个数组
        */
        function copyLastRowInTable($tableName, $attribName="", $attribValue="")
        {
            $objInfo = $this->getObjInfoById($tableName, $this->getMaxIdFromTable($tableName));
            list($num_fields, $fields) = $this->getCountOfColumns($tableName);//获取表的列
            $sqlString = "INSERT INTO ".$tableName." (";
            for($j=0; $j<$num_fields; $j++){
                $fields_name[$j] = @mysql_field_name($fields, $j);
                if($j==($num_fields-1))
                    $sqlString .= $fields_name[$j]."";
                else
                    $sqlString .= $fields_name[$j].",";
            }
            $sqlString .= ") VALUES(";
            for($j=0; $j<$num_fields; $j++){
                $tmpString = $objInfo->$fields_name[$j];
                if($fields_name[$j]==$tableName."_id")
                    $tmpString = "";
                for($i=0;$i<(sizeof($attribName));$i++){  //拆分属性 如果有相同的更新
                    if($fields_name[$j]==$attribName[$i]){
                        $tmpString = $attribValue[$i];
                    }
                }
                if($j==($num_fields-1))
                    $sqlString .= "'".$tmpString."'";
                else
                    $sqlString .= "'".$tmpString."',";
            }
            $sqlString .= ");";
            @mysql_query($sqlString);
        }
    /**
    * 分页函数
    * 参数们:
    * searchKey: 搜索的字段名,数组
    * searchWord: 对应字段名的关键字,数组
    * currentPage: 当前页数
    * numProPage: 每页显示记录数
    * pagesProPage: 显示前后几页
    * tableName: 数据表名称
    * allObjNumber: 是否为所有数据
    */
    function setPageForObjList($searchKey, $searchWord, $currentPage, $numProPage, $pagesProPage, $tableName, $allObjNumber, $id=0, $attribName="", $attribValue="", $operator="AND")
    {
    if(is_array($attribValue))
    {
    for($i=0;$i<sizeof($attribValue);$i++)
    {
    $sqlAttrib.="&attribValue[]=$attribValue[$i]";
    }
    }
    Global $currentSortKey;
    //是否为全部数据
    if($allObjNumber==0){
       list($allObj, $allObjNumber) = $this->getObjListByAttribArray( $tableName,  "" ,  $searchKey,  $searchWord,  $attribName,  $attribValue,  "",  "",  "", $operator , $id );
    }
    $pages = ceil($allObjNumber / $numProPage);   //总页数
    $pageOfPage = ceil($currentPage/$pagesProPage); //当前页

    $HtmlString = "<td bgcolor='#999999' width='80' align='center'><font face='Arial' style='font-size: 9pt' color='#FFFFFF'><b>$allObjNumber. <$currentPage/$pages></b></font></td>";

    if($pageOfPage>1){
    $curr_page = $pagesProPage*($pageOfPage-1);
    $HtmlString .= "<td width='16' align='center' valign='middle' bgcolor='#E8E8E8'>
    <a href='obj_list.php?currentPage=$curr_page&searchWord=$searchWord&currentSortKey=$currentSortKey&categoriesSelect=$categoriesSelect&limitNumber=$numProPage".$sqlAttrib."' target='objList'><img src='../../public_images/fore.gif' border='0'></a></td>";
    }
    else{
    $HtmlString .= "<td width='16' align='center' valign='middle' bgcolor='#E8E8E8'><img src='../../public_images/fore.gif'></td>";
    }
     for($i=($pageOfPage-1)*$pagesProPage+1;$i<=$pagesProPage*$pageOfPage;$i++){
    if($currentPage==$i){
    $color = "#999999";
    $fontcolor = "#FFFFFF";
    }
    else{
    $color = "#E8E8E8";
    $fontcolor = "#000000";
    }
    if($i>$pages){
    $HtmlString .= "<td align='center' width='16' bgcolor='#E8E8E8'>
    <font face='Verdana' style='font-size: 9pt;' color='#FFFFFF'></font></td>";
    }
    else{
    $HtmlString .= "<td width='16' align='center' bgcolor='$color'>
    <a href='obj_list.php?currentPage=$i&searchWord=$searchWord&currentSortKey=$currentSortKey&categoriesSelect=$categoriesSelect&limitNumber=$numProPage".$sqlAttrib."' target='objList'>
    <font face='Verdana' style='font-size: 9pt;' color='$fontcolor'><b>$i</b></font></a></td>";
    }
    }
    if($pageOfPage<ceil($pages/$pagesProPage)){
    $curr_page = $pagesProPage*$pageOfPage+1;
    $HtmlString .= "<td align='center' valign='middle' width='16' bgcolor='#E8E8E8'>
    <a href='obj_list.php?currentPage=$curr_page&searchWord=$searchWord&currentSortKey=$currentSortKey&categoriesSelect=$categoriesSelect&limitNumber=$numProPage".$sqlAttrib."' target='objList'><img src='../../public_images/next.gif' border='0'></a></td>";
    }
    else{
    $HtmlString .= "<td align='center' valign='middle' width='16' bgcolor='#E8E8E8'>
    <img src='../../public_images/next.gif' border='0'></td>";
    }
    return $HtmlString;
    }


    /**
    * 将分页显示在页面中
    * 参数多同函数setPageForObjList()
    */
    function showPage($searchKey, $searchWord, $currentPage, $limitNumber, $pagesProPage, $tableName, $attribName="", $attribValue="", $id=0, $operator="AND")
    {
    if(is_array($attribValue))
    {
    for($i=0;$i<sizeof($attribValue);$i++)
    {
    $sqlAttrib.="&attribValue[]=$attribValue[$i]";
    }
    }
    //输出外框
    echo'
    <div id="pageCount" style="position:absolute; left:200px; top:200px; z-index:1; display:none;">
      <table border="0" cellpadding="0" cellspacing="0" height="28">
       <tr>
    <td background="../../public_images/neikuang_1.gif" width="4" height="3"></td>
    <td width="180" background="../../public_images/neikuang_2.gif"></td>
    <td background="../../public_images/neikuang_3.gif" width="4" height="3"></td>
       </tr>
       <tr>
    <td background="../../public_images/neikuang_4.gif"></td>
    <td align="center" valign="middle">

    <table class="tablestyle" border="0" bordercolor="<?=$bgColor;?>" height="12">
     <tr>';
    //调用分页函数并输出结果
     echo $this->setPageForObjList($searchKey, $searchWord, $currentPage, $limitNumber, $pagesProPage, $tableName, 0, $id, $attribName , $attribValue, $operator);
    //输出外框结束
    echo'
      <td><input type="text" name="selectedPage" value="'.$currentPage.'" class="inputstyle" style="text-align:right; width: 27; height:16;" onkeyPress="gotoPage(objList,\'obj_list.php\',this.value,'.$limitNumber.',\''.$sqlAttrib.'\',\'&searchWord='.$searchWord.'\')"></td>
     </tr>
    </table>

    </td>
    <td background="../../public_images/neikuang_6.gif"></td>
       </tr>
       <tr>
    <td background="../../public_images/neikuang_7.gif" width="4" height="3"></td>
    <td background="../../public_images/neikuang_8.gif"></td>
    <td background="../../public_images/neikuang_9.gif" width="4" height="3"></td>
       </tr>
      </table>
    </div>
    <script language="javascript">
    parent.document.getElementById("pageCount").innerHTML="";
    parent.document.getElementById("pageCount").innerHTML=document.getElementById("pageCount").innerHTML;
    </script>';
    }


    }
       
      

  6.   

    现在用PDO,以前写的类都报废掉了.