正 文

MYSQL的操作类(已封装)


www.7dspace.com  更新日期:2005-11-3 6:57:54  七度空间


        function Execute($SQL)  //直接执行SQL语句
          {
                if(empty($SQL))
                  {
                        $this->nErr=1;
                        $this->sErr="Execute:执行语句不能为空!";
                        return false;
                  }
                 $this->sSQL=$SQL;
                  if(!mysql_query($SQL))
                  {
                          $this->nErr=1;
                          $this->sErr="Execute:SQL语句:".$SQL."<br>MySql错误:".mysql_error();
                          return false;
                  }
                  return true;
          }

    function Query($TableName="",$SQL="*",$Condition="",$Order="",$Sequenc="") //在数据库里执行查询
    {
      $this->Initialize();
      if(!empty($TableName))
        $this->sTName=$TableName;
      $strSQL="select ".$SQL." from ".$this->sTName;
      if(!empty($Condition))
        $strSQL=$strSQL." where ".$Condition;
      if(!empty($Order))
        $strSQL=$strSQL." order by ".$Order;
      if(!empty($Sequenc))
        $strSQL=$strSQL." ".$Sequenc;
          $this->sSQL=$strSQL;
      if(!$this->nResult=mysql_query($strSQL))
      {
        $this->nErr=1;
        $this->sErr="Query:SQL语句:".$strSQL."<br>MySql错误:".mysql_error()."<br>";
        return;
      }
      $this->nOffset=0;
      $this->nRows=mysql_num_rows($this->nResult);
      $this->nCols=mysql_num_fields($this->nResult);
          if($this->nRows>0)
                  $this->EOF=false;
          else
                  $this->EOF=true;
      unset($this->aFName);
      $this->aFName=array();
      for($i=0;$i<$this->nCols;$i++)
         $this->aFName[$i]=strtolower(mysql_field_name($this->nResult,$i));
    }

        function MoveNext()
          {
                if($this->EOF)
                  {
                        $this->nErr=1;
                        $this->sErr="MoveNext:已经移到记录集末尾!";
                        return;
                  }
                $this->nOffset++;
                if($this->nOffset>=$this->nRows)
                        $this->EOF=true;
          }

     function MoveTo($Offset)
     {
        if(empty($Offset))
        {
          $this->nErr=1;
          $this->sErr="MoveTo:必须指定偏移量! ";
          return;
        }

        if(!$this->nResult)
        {
          $this->nErr=1;
          $this->sErr="MoveTo:请先执行查询:Query";
          return;
        }
        $this->nOffset=$Offset;
     }

6页,页码:[1] [2] [3] [4] [5] [6] 

上一篇:使用XML-RPC来访问Web服务
下一篇:Windows系统自动保存密码再现
作者:熊毅(小熊)  来源:CSDN ( 责任编辑:7dspace )
收藏此页】【打印】【关闭
站 内 搜 索
 

热 点 导 读
特 别 推 荐