打印本文 打印本文 关闭窗口 关闭窗口
MYSQL的操作类(修改后的新版本)
作者:武汉SEO闵涛  文章来源:敏韬网  点击数3086  更新时间:2009/4/22 20:48:46  文章录入:mintao  责任编辑:mintao
;  $this->aNew=array();
      $this->NewEdit=1;
      $strSQL="select * from ".$this->sTName;
          $this->sSQL=$strSQL;
      if(!$this->nResult=mysql_query($strSQL))
      {
        $this->nErr=1;
        $this->sErr="AddNew:SQL语句:".strSQL."<br><br>MySql错误:".mysql_error();
        return;
      }
      $this->nCols=mysql_num_fields($this->nResult);
      unset($this->aFName);
      $this->aFName=array();
      for($i=0;$i<$this->nCols;$i++)
         $this->aFName[$i]=strtolower(mysql_field_name($this->nResult,$i));
    }

    function Edit($Condition="",$TableName="")  //对指定数据库表进行编辑
    {
                  $this->Initialize();
                  if(!empty($TableName))
                          $this->sTName=$TableName;
                  $this->sEditCon=$Condition;
                  if(empty($this->sTName))
                  {
                          $this->nErr=1;
                          $this->sErr="Edit:在编辑前请先指定数据库表!";
                          return;
                  }
                  unset($this->aNew);
                  $this->aNew=array();
                  $this->NewEdit=2;
                  $strSQL="select * from ".$this->sTName;
                  $this->sSQL=$strSQL;
                  if(!$this->nResult=mysql_query($strSQL))
          {
             $this->nErr=1;
             $this->sErr="Edit:SQL语句:".strSQL."<br><br>MySql错误:".mysql_error();
             return;
          }
          $this->nCols=mysql_num_fields($this->nResult);
          unset($this->aFName);
          $this->aFName=array();
          for($i=0;$i<$this->nCols;$i++)
             $this->aFName[$i]=strtolower(mysql_field_name($this->nResult,$i));
    }

    function SetValue($Index,$Value) //指定数据,跟在AddNew后执行;
    {
             if($this->NewEdit==0)
             {
                $this->nErr=1;
                $this->sErr="SetValue:请先执行AddNew()或者Edit()!";
                return;
             }
             if(is_int($Index))
             {
                 if($Index<0||$Index>$this->nCols)
                 {
                    $this->nErr=1;
                    $this->sErr="SetValue:插入不存在的列值!";
                    return;
                 }
                 $this->aNew[$Index]=$Value;
                 $tmpIn=$Index;
             }
             elseif(is_string($Index))
             {
                $Index=strtolower($Index);
                for($i=0;$i<$this->nCols;$i++)
                {
                    if($this->aFName[$i]==$Index)
                       break;
                }
                if($i==$this->nCols)
                {
                    $this->nErr=1;
                    $this->sErr="SetValue:插入不存在的列值!";
                    return;
                 }
                 $this->aNew[$i]=$Value;
                 $tmpIn=$i;
             }
                 if(!empty($this->sName))
                    $this->sName.=",";
                 $this->sName.=$this->aFName[$tmpIn];
                 //根据当前字段的类型生成相应的新值
                 if($this->sValue!="#@!")
                    $this->sValue.=",";
                 else
                    $this->sValue="";
                 $ftype=@mysql_field_type($this->nResult,$i);
                 //echo($ftype.",".$this->aNew[$i].",".$i.":".$sValue."<br>");
                
                 switch($ftype)
   &n

上一页  [1] [2] [3] [4]  下一页

打印本文 打印本文 关闭窗口 关闭窗口