db.class.php 1.01 KB
<?php
define('DB_DIR', "DB/");
require_once("libs/db/DB.php");
require_once("libs/db/PAGER/Pager_Wrapper.php");
class sdb{

/*** Declare instance ***/
private static $instance = NULL;

/**
*
* the constructor is set to private so
* so nobody can create a new instance using new
*
*/
private function __construct() {
  /*** maybe set the db name here later ***/
}

/**
*
* Return DB instance or create intitial connection
*
* @return object (PDO)
*
* @access public
*
*/
public static function getInstance() {

if (!self::$instance)
    {
    $connect = "mysql://" . Config::get('DB_USER') . ":" . Config::get('DB_PSW') . "@" . Config::get('DB_HOST') . "/" . Config::get('DB_BASE');
    self::$instance = DB::connect($connect);
    if (PEAR::isError(self::$instance)) die(self::$instance->getMessage());
    self::$instance->query("set names cp1251");
    }
return self::$instance;
}

/**
*
* Like the constructor, we make __clone private
* so nobody can clone the instance
*
*/
private function __clone(){
}

} /*** end of class ***/

?>