Location: PHPKode > scripts > mysql_db class > mysql_db-class/mysql_command.php
<?PHP
// MYSQL_COMMAND: SQL execution framework for MYSQL_DB
// Release 1.1 - 06/08/2002
// Released under GNU GPL (see LICENSE for details)

class mysql_command {
  // Init variables required
  VAR $connobj      = "" ;
  VAR $sqlstring    = "" ;
  // Data related variables
  VAR $rs ;
  VAR $recordcount  = 0 ;
  VAR $EOF          = true ;
  VAR $lastid       = 0 ;
  // --------- Private methods ---------
  // Executing a command
  function exec_command()
    {
    // Determine if there is an open database and we have an SQL command to execute...
    if ($GLOBALS[$this->connobj]->db && $this->sqlstring!="") {
      $this->rs = mysql_query($this->sqlstring,$GLOBALS[$this->connobj]->db) ;	
      $GLOBALS[$this->connobj]->error_report() ;
      // Affectected rows...
      if ($this->rs) {
        // Execution was o.k.
        $this->EOF = true ;
        $this->recordcount = mysql_affected_rows() ;
        $this->lastid = mysql_insert_id() ;
        $GLOBALS[$this->connobj]->msg =  date("d/m/Y - H:i:s") . " - OPERATION O.K.: Executed " . $this->sqlstring ." affected " . $this->recordcount . " rows" . "\r\n" ;
      } else {
        // Execution Failed
        $this->recordcount = 0 ;
        $this->EOF = true ;
        $GLOBALS[$this->connobj]->error_report() ;
        $GLOBALS[$this->connobj]->msg =  date("d/m/Y - H:i:s") . " - OPERATION FAILED: Executed " . $this->sqlstring . " got " . $GLOBALS[$this->connobj]->error_level . " " . $GLOBALS[$this->connobj]->error_desc . "\r\n";
        }
    } else {
      // No database ready to query
      $this->recordcount = 0 ;
      $this->EOF = true ;
      $GLOBALS[$this->connobj]->msg =  date("d/m/Y - H:i:s") . " - OPERATION FAILED: No database open OR no SQL command provided" . "\r\n" ;
      }
    $GLOBALS[$this->connobj]->debug() ;
    }
  // --------- Public interface ---------
  // Executing an sql command
  function execute()
    {
    $this->exec_command() ;
    return $this->recordcount ;
    }
  // Constructor...
  function mysql_command($connobjname,$sqlcommand)
    {
    $this->connobj    = $connobjname ;
    $this->sqlstring  = $sqlcommand ;
    }
  }
?>
Return current item: mysql_db class