Location: PHPKode > scripts > DBInterface > adodb.php
<?php
//requires ADODb lib, e.g. require_once "adodb5/adodb.inc.php";  
class ADODB_DB extends DB
{
   public $db = '';

   public function connect($engine='mysql')
   {
      $this->db = NewADOConnection($engine);
      $this->db->Connect($this->host, $this->username, $this->password, $this->database);
      //$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
      return;
   }

   public function table_columns($table)
   {
      return $this->db->MetaColumnNames($table,true);
   }

   public function close()
   {
      return $this->db->Close();
   }

   public function query($qry)
   {
      return $this->db->Execute($qry);
   }

   public function fetch_query($qry,$assoc=1)
   {
      $data = array();
      if ($assoc=0)
         $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
      $result = $this->db->Execute($qry);
      if ($result === false)
         return $data;
      while (!$result->EOF)
      {
         $data[] = $result->fields;
         $result->MoveNext();
      }
      $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
      return $data;
   }

   public function row($res)
   {
      $ret = $res->fields;
      $res->MoveNext();
      return $ret;
   }

   public function next_id($table)
   {
      return $this->db->GenID($table);
   }

   public function last_id()
   {
      return $this->db->Insert_ID();
   }

   public function insert($table,$values=array(),$columns=array())
   {
      $sql = "INSERT INTO $table ";
      if (!empty($columns))
      {
         $sql .= '(';
         foreach ($columns as $col)
         {
            $sql .= "'$col',";
         }
         $sql = substr($sql,0,strlen($sql)-1);
         $sql .= ') ';
      }
      if (empty($values))
      {
          for ($i=0; $i < count($columns); $i++)
          {
             $values[$i] = '';
          }
      }
      $sql .= "VALUES(";
      foreach ($values as $val)
      {
         $sql .= "'$val',";
      }
      $sql = substr($sql,0,strlen($sql)-1);
      $sql .= ');';
      return $this->db->Execute($sql);
   }

   public function update($table,$values,$where,$limit=0)
   {
      $sql = "UPDATE $table SET ";
      foreach ($values as $key => $val)
      {
         $sql .= $key." = '$val', ";
      }
      $sql = substr($sql,0,strlen($sql)-2);
      $sql = $sql." WHERE $where";
      if ($limit != 0)
         $sql .= " LIMIT $limit";
      return $this->db->Execute($sql);
   }

   public function delete($table,$where,$limit=0)
   {
       $sql = "DELETE FROM $table WHERE $where";
       if ($limit != 0)
          $sql .= " LIMIT $limit";
       return $this->db->Execute($sql);
   }

   public function table_info($table)
   {
      return $this->db->MetaColumns($table);
   }

   public function use_db($dbn)
   {
      $this->database = $dbn;
      $this->db->Close();
      $this->db->Connect($this->host, $this->username, $this->password, $this->database);
   }

   public function escape_str($str,$quotes=0,$exchars = '')
   {
      if (is_array($str))
      {
         $str = array_map(array('ADO_DB','escape_str'),$str);
      }
      else
      {
         if (get_magic_quotes_gpc()) {
             $str = stripslashes($str);
         }
         if (!is_numeric($str)) {
            $str = addslashes($str);
            $str = str_replace("\r",chr(92).'r',$str);
            $str = str_replace("\n",chr(92).'n',$str);
            if (!empty($exchars))
               for ($i=0; $i<strlen($exchars); $i++)
                  $str = str_replace($exchars[$i],chr(92).$exchars[$i],$str);
            if ($quotes)
               $str = "'".$str."'";
         }
      }
      return $str;
   }

   public function num_rows($res)
   {
      return $res->RecordCount();
   }

   public function affected_rows($res)
   {
      return $this->db->Affected_Rows();
   }

   public function num_fields($res)
   {
      return count($res->fields);
   }
}
?>
Return current item: DBInterface