<?php
 
/*
  * This is a PHP class definition for MySQL database server connections.
  *
  * ------------------------------------------------------------------------------
  * "THE BEER-WARE LICENSE" (Revision 42):
  * <giversen@netadmins.dk> wrote this file. As long as you retain this notice you
  * can do whatever you want with this stuff. If we meet some day, and you think
  * this stuff is worth it, you can buy me a beer in return. Anders Giversen
  * ------------------------------------------------------------------------------
  */
  
  
class MySQL_class {
    
    var 
$linkid$db$result$numRows$curRow$affRows$data;
    
    function 
MySQL_class($host$db$user$pass) {
      
$this->linkid = @mysql_pconnect($host$user$pass);
      if (!
$this->linkid) {
        
$this->MySQL_ErrorMsg("Sorry, not able to process query right now!");
      }
      
      
$this->selectDB($db);
    } 
// MySQL_class
    
    
function selectDB($db) {
      @
mysql_select_db($db$this->linkid) or $this->MySQL_ErrorMsg("Unable to select database!");
      
      
$this->db $db;
    } 
// selectDB
    
    
function Query($query) {
      
$this->result = @mysql_query($query$this->linkid);
      if (!
$this->result) {
        
$this->numRows 0;
        
$this->curRow 0;
        
        return 
false;
      } else {
        
$this->numRows = @mysql_num_rows($this->result);
        
$this->curRow 0;
        
        return 
true;
      }
    } 
// Query
    
    
function fetchRow($row) {
      @
mysql_data_seek($this->result$row) or $this->MySQL_ErrorMsg("Unable to seek data row: $row");
      
      
$this->data = @mysql_fetch_array($this->result);
      if (!
$this->data) {
        return 
false;
      } else {
        return 
$this->data;
      }
    } 
// fetchRow
    
    
function getNext() {
      if (
$this->curRow $this->numRows) {
        if (
$this->fetchRow($this->curRow)) {
          
$this->curRow++;
          
          return 
$this->data;
        } else {
          return 
false;
        }
      } else {
        return 
false;
      }
    } 
// getNext
    
    
function Insert($query) {
      
$this->result = @mysql_query($query$this->linkid);
      if (!
$this->result) {
        
$this->affRows 0;
        
        
$this->MySQL_ErrorMsg("Unable to perform insert!");
      } else {
        
$this->affRows = @mysql_affected_rows($this->linkid);
        
        return 
$this->result;
      }
    } 
// Insert
    
    
function Update($query) {
      
$this->result = @mysql_query($query$this->linkid);
      if (!
$this->result) {
        
$this->affRows 0;
        
        
$this->MySQL_ErrorMsg("Unable to perform update!");
      } else {
        
$this->affRows = @mysql_affected_rows($this->linkid);
        
        return 
$this->result;
      }
    } 
// Update
    
    
function Delete($query) {
      
$this->result = @mysql_query($query$this->linkid);
      if (!
$this->result) {
        
$this->affRows 0;
        
        
$this->MySQL_ErrorMsg("Unable to perform delete!");
      } else {
        
$this->affRows = @mysql_affected_rows($this->linkid);
        
        return 
$this->result;
      }
    } 
// Delete
    
    
function getAffectedRows() {
      return 
$this->affRows;
    } 
// getAffectedRows
    
    
function getNumRows() {
      return 
$this->numRows;
    } 
// getNumRows
    
    
function getTableList() {
      
$this->result = @mysql_list_tables($this->db$this->linkid);
      if (!
$this->result) {
        
$this->MySQL_ErrorMsg("Unable to find any tables in database!");
      } else {
        
$this->numRows = @mysql_num_rows($this->result);
        
$i 0;
        
        
$tbList = array();
        
        while (
$i $this->numRows) {
          
$tbList[$i] = @mysql_tablename($this->result$i);
          
$i++;
        }
        
        return 
$tbList;
      }
    } 
// getTableList
    
    
function MySQL_ErrorMsg($msg) {
      exit(
$msg);
    } 
// MySQL_ErrorMsg
    
  
// class MySQL_class
  
?>