日期:2014-05-16  浏览次数:20749 次

mysql操作类
<?php
class MySQL
{
       var $serverName        = '';       //数据库主机
       var $admin              ='';
       var $password              ='';
       var $dbName               = '';       //数据库名
       var $dbUsername        = '';       // 数据库用户名
       var $dbPassword        = '';       // 数据库密码
       var $usePconnect        = 0;
       var $website        ='';
       var $id                             = 0;
       var $linkId                      = 0;
       var $queryId               = 0;

       var $queryCount        = 0;
       var $result;
       var $record               = array();
       var $rows;
       var $affectedRows = 0;
       var $insertId;

       var $errno;
       var $error;

       var $queryLog = array();

       function GetErrDesc()
       {
              $this->error = @mysql_error( $this->linkId );
              return $this->error;
       } 

       function GetErrNo()
       {
              $this->errno = @mysql_errno( $this->linkId );
              return $this->errno;
       } 

       function Connect()
       {
              if ( $this->usePconnect == 1 )
              {
                     if ( !$this->linkId = @mysql_pconnect( $this->serverName, $this->dbUsername, $this->dbPassword ) )
                            $this->Halt( 'Connect faild!' );
              }
              else
              {
                     if ( !$this->linkId = @mysql_connect( $this->serverName, $this->dbUsername, $this->dbPassword ) )
                            $this->Halt( 'Connect faild!' );
              } 
              return $this->linkId;
       } 

       function SelectDB()
       {
              if ( !mysql_select_db( $this->dbName ) )
                     $this->Halt( 'Connect faild!' );
       } 

       function Query( $queryStr )
       {
              $this->result = mysql_query( $queryStr, $this->linkId );
              if ( !$this->result )
                     $this->Halt( 'Invalid SQL: ' . $queryStr );
              return $this->result;
       } 

       function Update( $queryStr )
       {
              $this->Query( $queryStr );
              return $this->AffectedRows();
       }

       function FetchArray( $queryId, $fetchType = 'assoc' )
       {
              if ( empty( $queryId ) )
                     $this->Halt( 'Invalid query id:' . $queryId );

              if ( $fetchType = 'assoc' )
                     $this->record = mysql_fetch_assoc( $queryId );
              else
                     $this->record = mysql_fetch_array( $queryId );

              return $this->record;
       }

       function FetchRow( $queryId )
       {
              if ( empty( $queryId ) )
                     $this->Halt( 'Invalid query id:' . $queryId );

              $this->record = mysql_fetch_row( $queryId );
              return $this->record;
       }

       function FetchOne( $query, $field = '' )
       {
              if ( empty( $query ) )
                     $this->Halt( 'Invalid query id:' . $query );
              $this->result = $this->Query( $query );
              $this->record = $this->FetchArray( $this->result );
              if ( $field != '' )
                     return $this->record[$field];
              else
                     return $this->record;
       }

       function FetchAll( $query, $field = '' )
       {
              if ( empty( $query ) )
                     $this->Halt( 'Invalid query id:' . $query );

              $this->result = $this->Query( $query );
              if ( $field != '' )
              {
                     while ( $this->record = $this->FetchArray( $this->result ) )
                            $result[] = $this->record[$field];
              }
              else
              {
                     while ( $this->record = $this->Fetc