Blame view

application/db.class.php 1.01 KB
8d65d0ce   andryeyev   init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
  <?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 ***/
  
  ?>