Location: PHPKode > scripts > XML-RPC DB > inc/DBconnection.php
<?php
 /*
 *********************************************************************************************************
 * PHP Web Platform
 *
 * Authors:	Giulio Calzolari <hide@address.com>
 *********************************************************************************************************
 */
 

include "Define.inc";

include_once("adodb/adodb.inc.php");
include_once("adodb/adodb-exceptions.inc.php"); 


class DBConnection
{
   private $_db;
   private $_lastSQL;
   private $_debugsql;
   private $_old_debugsql;

   // Hold an instance of the class
   static private $unique_instance;
   static public function instance() {
     if (!isset(self::$unique_instance)) {
       $c = __CLASS__;
       self::$unique_instance = new $c;
       self::$unique_instance->connect();
     }
     
     return self::$unique_instance;
   }  
 
   
 // temporary method  
   function &adodb() 
   {
      return $this->_db;
   }
   
   function __construct($type = null)
   {

      try
        {
         $this->_db = &ADONewConnection(DB_DRIVER);
        }
         catch (ADODB_Exception $e) { var_dump($e);}
   }
   
   function connect($server = null, $user = null, $passwd = null, $database = null, $clientFlags = null)
   {

     if ($user     == null) $user     = DB_USER;
     if ($passwd   == null) $passwd   = DB_PASSWD;
     if ($server   == null) $server   = DB_HOST;
     if ($database == null) $database = DB_NAME;
     if ($clientFlags == null) $clientFlags = ADODB_CLIENT_FLAG;
  
     $this->_log = DB_SQLLOG;
     $this->_db->SetFetchMode(ADODB_ASSOC_CASE);

      try
        {
          return $this->_db->Connect($server, $user, $passwd,$database);
        }
         catch (ADODB_Exception $e) { var_dump($e);} 
         
   }
   
   
   function executeSQL(&$sql)
   {
      if ($this->_log != null && $this->_debugsql == 'enable' ) {
        $fd = fopen($this->_log,"a+");
        fwrite($fd, date("Y-m-d H:i:s").": ".$sql."\r\n");
        fclose($fd);
      }
         $result = $this->_db->Execute($sql);
         return $result;  
   }
     
   function SetFetchMode($mode)
   {
      $this->_db->SetFetchMode($mode);
   }
   
   function SetFetchModeDefault()
   {
      $this->_db->SetFetchMode(ADODB_ASSOC_CASE);
   }
   

}

?>
Return current item: XML-RPC DB