public static function getInstance()
 {
     if (!self::$_instance instanceof Database) {
         self::$_instance = new Database();
     }
     return self::$_instance;
 }
示例#2
0
 /**
  * If an instance of this class has been not been instantiated quite yet, this
  * function will create, cache and return the instance. If the instance of
  * this class has already been instantiated and cached, the cached version of
  * this class instantiation will be returned. Thus, adhering to the rules of
  * singleton's.
  *
  * @return Database The singleton instance of this class. Only ever
  *  instantiated but one time.
  */
 public static function instance()
 {
     if (!self::$_instance instanceof self) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
示例#3
0
 public static function getInstance()
 {
     if (self::$_instance == null) {
         self::$_instance = new Database();
     }
     return self::$_instance;
 }
示例#4
0
 public static function singleton()
 {
     if (!is_object(self::$_instance)) {
         self::$_instance = new Database();
     }
     return self::$_instance;
 }
示例#5
0
 public static function getInstance()
 {
     if (!isset(self::$_instance)) {
         self::$_instance = new Database();
     }
     return self::$_instance;
 }
示例#6
0
 /**
  * Setup the instance (singleton)
  *
  * @param $config array
  * @return Database
  */
 public static function getInstance($config = '')
 {
     if (!self::$_instance instanceof self) {
         self::$_instance = new self($config);
     }
     return self::$_instance;
 }
示例#7
0
 public static function getInstance()
 {
     if (!self::$_instance) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
示例#8
0
 public static function getInstance()
 {
     if (!self::$_instance) {
         // Se não houver uma instancia, cria uma
         self::$_instance = new self();
     }
     return self::$_instance;
 }
示例#9
0
 /**
  *	获得数据库连接实例对象
  */
 public static function getInstance()
 {
     if (!isset(self::$_instance)) {
         self::$_instance = new self();
     }
     //echo '输出实例';
     return self::$_instance;
 }
 /**
  *	Instantiates the singleton.  Checks to make sure there is no instance
  *	already instantiated by looking at the static property $_instance.  If
  *	it doesn't exist, created it.  Otherwise return the handle to this
  *	resource.
  *
  *	Acts as the constructor for this class.
  *
  *	@param		$dbLoc		Location of the MySQL database.
  *	@param		$dbName		Name of the database being used.
  *	@param		$dbUser		Username with access to database.
  *	@param		$dbPass		Password for the database user.
  *	@return		Resource handle
  */
 public static function start($dbLoc, $dbName, $dbUser, $dbPass)
 {
     if (!isset(self::$_instance)) {
         $c = __CLASS__;
         self::$_instance = new $c($dbLoc, $dbName, $dbUser, $dbPass);
     }
     return self::$_instance;
 }
示例#11
0
 static function getInstance()
 {
     /*Creates an instance of this object if none exists and returns it.*/
     if (self::$_instance === null) {
         self::$_instance = new Database();
     }
     return self::$_instance;
 }
示例#12
0
 public static function getInstance()
 {
     if (self::$_instance === null) {
         $settings = Settings::getInstance();
         self::$_instance = new self($settings->db_host(), $settings->db_name(), $settings->db_user(), $settings->db_pass());
     }
     return self::$_instance;
 }
示例#13
0
 static function getInstance()
 {
     if (!self::$_instance) {
         self::$_instance = new self();
     }
     return self::$_instance;
     //als er al een instantie van de database classe is aangemaakt, dan wordt deze instantie zelf teruggeven (zodat er maar 1 databaseconnectie is).
 }
示例#14
0
 /**
  * @desc get an instance of the Database
  * @params none
  * @return Instance
  */
 public static function getInstance()
 {
     if (!self::$_instance) {
         // If no instance then make one
         self::$_instance = new self();
     }
     return self::$_instance;
 }
示例#15
0
 static function getInstance()
 {
     /*Creates an instance of this object if none exists and returns it.*/
     if (!self::$_instance) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
示例#16
0
 public function getInstance()
 {
     if (!isset(self::$_instance)) {
         // :: wywoluje metody klas bez tworzenia instancji obiektow (statyczne wywolanie metody)
         self::$_instance = new Database();
         // wywolujemy instance i przypisujemy
     }
     return self::$_instance;
 }
示例#17
0
 /**
  * The constructor initializes the database connection.
  * 
  * @param string $host
  * @param string $username
  * @param string $password
  * @param string $db
  * @param int $port
  */
 public function __construct($host, $username, $password, $db, $port = NULL)
 {
     if ($port == NULL) {
         $port = ini_get('mysqli.default_port');
     }
     $this->_mysqli = new mysqli($host, $username, $password, $db, $port) or die('There was a problem connecting to the database');
     $this->_mysqli->set_charset('utf8');
     self::$_instance = $this;
 }
示例#18
0
 /**
  * @return Database
  */
 public static function getInstance()
 {
     if (!self::$_instance instanceof self) {
         $config = parse_ini_file("./config/config.ini", true);
         $config = $config["database"];
         self::$_instance = new self($config["host"], $config["username"], $config["password"], $config["database"]);
     }
     return self::$_instance;
 }
示例#19
0
 public static function getInstance()
 {
     /*
      If there is no instance then create instance
      self is used to refer current class
     */
     if (!self::$_instance) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
示例#20
0
 public static function getInstance()
 {
     // es wird geprüft, ob bereits eine Instanz exisitiert
     if (!self::$_instance) {
         // falls keine Instanz existiert,
         // dann wird einfach eine neue angelegt
         self::$_instance = new Database();
     }
     // die Instanz wird zurückgegeben
     return self::$_instance;
 }
 public static function getInstance()
 {
     if (!isset(self::$_instance)) {
         try {
             self::$_instance = new PDO('mysql:dbname=' . self::$_db . ';host=' . self::$_host, self::$_user, self::$_pass, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
         } catch (PDOException $e) {
             echo 'Connection à MySQL impossible : ', $e->getMessage();
         }
     }
     return self::$_instance;
 }
示例#22
0
 /**
  * Retrieve a database connection with the given connection parameters. Will create connection if none exists
  * @static getConnection
  *
  * @param  array $connectionParams
  *
  * @return Database Database Instance
  */
 public static function getConnection($connectionParams)
 {
     /*
      * Returns the last database connection if available,
      * otherwise initializes a new database connection
      */
     if (self::$_instance) {
         return self::$_instance;
     } else {
         self::$_instance = new Database($connectionParams);
         return self::$_instance;
     }
 }
示例#23
0
 public function __construct($host, $username, $password, $db, $port = null)
 {
     // Get the default port number if not given.
     if ($port == null) {
         $port = ini_get('mysqli.default_port');
     }
     $this->_mysqli = @new mysqli($host, $username, $password, $db, $port);
     if (!$this->_mysqli) {
         die($this->error('There was a problem connecting to the database'));
     }
     $this->_mysqli->set_charset('utf8');
     self::$_instance = $this;
     $this->debug_array = array('host' => $host, 'username' => $username, 'database' => $db);
 }
    public static function getInstance()
    {
        if (null === self::$_instance) {
            try {
                self::$_instance = new PDO('mysql:host=' . HOST . ';
				dbname=' . DB . ';
				port=' . PORT . ';
				connect_timeout=15', USER, PASS);
            } catch (PDOException $err) {
                echo $err->getMessage();
            }
        }
        return self::$_instance;
    }
 public function __construct()
 {
     $port = 3306;
     // Get the default port number if not given.
     if ($port == null) {
         $port = ini_get('mysqli.default_port');
     }
     $this->_mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME, $port);
     if (!$this->_mysqli) {
         die($this->error('There was a problem connecting to the database'));
     }
     $this->_mysqli->set_charset('utf8');
     self::$_instance = $this;
     $this->debug_array = array('host' => DB_HOST, 'username' => DB_USER, 'database' => DB_NAME);
 }
示例#26
0
 /**
  * @param string $host
  * @param string $username
  * @param string $password
  * @param string $db
  * @param int $port
  */
 public function __construct()
 {
     if (!isset($port)) {
         $port = ini_get('mysqli.default_port');
     }
     if (file_exists("config.php")) {
         include "config.php";
     } else {
         Messages::addMessage("Config file does not exist", Messages::ERRO);
         return;
     }
     $this->_mysqli = new mysqli($db['db_host'], $db['db_user'], $db['db_pass'], $db['db_base'], $port);
     $this->_mysqli->set_charset('utf8');
     self::$_instance = $this;
 }
 public function get_instance()
 {
     if (self::$_instance === NULL) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
示例#28
0
    public function __construct($mode = 0)
    {
        self::$_instance = $this;
        if ($mode == 0) {
            require './cms/config/db_settings.conf.php';
        } else {
            require './config/db_settings.conf.php';
        }
        self::$db_settings = $db_settings;
        switch (self::$db_settings['type']) {
            case 'sqlite':
                if ($mode == 0) {
                    self::$content = new PDO('sqlite:' . self::$db_settings['db_content_file']);
                    self::$entries = new PDO('sqlite:' . self::$db_settings['db_entry_file']);
                    #self::$content = new PDO('sqlite:'.self::$db_settings['db_content_file'], NULL, NULL, array(PDO::ATTR_PERSISTENT => TRUE));
                    #self::$entries = new PDO('sqlite:'.self::$db_settings['db_entry_file'], NULL, NULL, array(PDO::ATTR_PERSISTENT => TRUE));
                    self::$content->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                    self::$entries->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                }
                if ($mode == 1) {
                    self::$content = new PDO('sqlite:../' . self::$db_settings['db_content_file']);
                    self::$entries = new PDO('sqlite:../' . self::$db_settings['db_entry_file']);
                    self::$userdata = new PDO('sqlite:../' . self::$db_settings['db_userdata_file']);
                    self::$content->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                    self::$entries->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                    self::$userdata->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                }
                break;
            case 'sqlite2':
                if ($mode == 0) {
                    self::$content = new PDO('sqlite2:' . self::$db_settings['db_content_file']);
                    self::$entries = new PDO('sqlite2:' . self::$db_settings['db_entry_file']);
                }
                if ($mode == 1) {
                    self::$content = new PDO('sqlite2:../' . self::$db_settings['db_content_file']);
                    self::$entries = new PDO('sqlite2:../' . self::$db_settings['db_entry_file']);
                    self::$userdata = new PDO('sqlite2:../' . self::$db_settings['db_userdata_file']);
                }
                break;
            case 'mysql':
                self::$complete = new PDO('mysql:host=' . self::$db_settings['host'] . ';port=' . self::$db_settings['port'] . ';dbname=' . self::$db_settings['database'], self::$db_settings['user'], self::$db_settings['password']);
                self::$complete->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                self::$complete->query("set names utf8");
                self::$content =& self::$complete;
                self::$entries =& self::$complete;
                if ($mode == 1) {
                    self::$userdata =& self::$complete;
                }
                break;
            case 'postgresql':
                self::$complete = new PDO('pgsql:dbname=' . self::$db_settings['database'] . ';host=' . self::$db_settings['host'] . ';user='******'user'] . ';password='******'password']);
                self::$complete->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                #self::$complete->query("set names utf8");
                self::$content =& self::$complete;
                self::$entries =& self::$complete;
                if ($mode == 1) {
                    self::$userdata =& self::$complete;
                }
                break;
            default:
                ?>
<p>Database type not supported.</p><?php 
                exit;
        }
    }
示例#29
0
 /**
  * @param string $host
  * @param string $username
  * @param string $password
  * @param string $db
  * @param int $port
  * @param string $charset
  */
 public function __construct($host = null, $username = null, $password = null, $db = null, $port = null, $charset = 'utf8')
 {
     $isSubQuery = false;
     $config = Config::getConfig();
     // if params were passed as array
     if (is_array($host)) {
         foreach ($host as $key => $val) {
             ${$key} = $val;
         }
     }
     // if host were set as mysqli socket
     if (is_object($host)) {
         $this->_mysqli = $host;
     } else {
         $this->host = $host ?: $config->get('host');
     }
     $this->username = $username ?: $config->get('username');
     $this->password = $password ?: $config->get('password');
     $this->db = $db ?: $config->get('database');
     $this->port = $port ?: $config->get('port');
     $this->charset = $charset ?: $config->get('charset');
     if ($isSubQuery) {
         $this->isSubQuery = true;
         return;
     }
     if (isset($prefix)) {
         $this->setPrefix($prefix);
     }
     self::$_instance = $this;
 }
示例#30
0
 public function __construct()
 {
     parent::__construct();
     $this->_mysqli = new mysqli('localhost', $this->config['db']['user'], $this->config['db']['pass'], $this->config['db']['db']) or die('There was a problem connecting to the database');
     self::$_instance = $this;
 }