public static function get() { if (is_null(self::$instance)) { self::$instance = self::openConnection(); } return self::$instance; }
public static function getInstance() { if (!isset(self::$instance)) { self::$instance = new Connection(); } return self::$instance; }
/** * Get a singleton instance of Connection<object> * * @return Connection */ public static function get_instance() { if (self::$instance === null) { self::$instance = new Connection(); } return self::$instance; }
public static function open() { if (self::$instance == null) { $klass = __CLASS__; self::$instance = new $klass('localhost', 'root', "", 'impaz'); } return self::$instance; }
public static function getInstance() { if (self::$instance == null) { self::$instance = new self(self::HOST, self::USER, self::PASSWORD, self::DATABASE); self::$instance->query("SET NAMES 'utf8'"); } return self::$instance; }
public static function instance() { if (!isset(self::$instance)) { $c = __CLASS__; self::$instance = new $c(); } return self::$instance; }
public static function getInstance() { if (!isset(self::$instance)) { $pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION; self::$instance = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_SCHEMA, DB_USERNAME, DB_PASSWORD, $pdo_options); } return self::$instance; }
/** * If $name is null then the default connection will be returned. * * @see Config * @param string $name Optional name of a connection * @return Connection */ public static function get_connection($name = null) { $config = Config::instance(); $name = $name ? $name : $config->get_default_connection(); if (!isset(self::$connections[$name]) || !self::$connections[$name]->connection) { self::$connections[$name] = Connection::instance($config->get_connection($name)); } return self::$connections[$name]; }
private function __construct() { try { self::$instance = new PDO('mysql:host=localhost;port=3306;dbname=biblioteca;charset=utf8', 'root', 'qwe123'); self::$instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { die("Erro no banco de dados: " . $e->getMessage()); } }
/** * Constuctor de la clase haciendo uso del patrón Singletón * @return Connection */ public function __construct() { if (!self::$instance) { $this->loadProxyMySql(); $this->loadProxySoap(); self::$instance = $this; } return self::$instance; }
public function remove($table, $columns, $options = array()) { $name = $this->getName($columns, $options); if ($name === 'PRIMARY') { $sql = "ALTER TABLE `{$table}` DROP PRIMARY KEY"; } else { $sql = "ALTER TABLE `{$table}` DROP INDEX `{$name}`"; } return Connection::instance()->execute($sql); }
private function __construct() { try { Connection::$instance = new PDO("mysql:host={$this->servername};dbname={$this->dbName}", $this->username, $this->password); // set the PDO error mode to exception Connection::$instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo "Connected successfully"; } catch (PDOException $e) { echo "Connection failed: " . $e->getMessage(); } }
/** * Singleton method that requests a unique instance of the class * * @return object (PDO) * @access public */ public static function getInstance() { if (!self::$instance instanceof self) { try { self::$instance = new self(); self::$instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { echo 'Connection failed: ' . $e->getMessage(); } } return self::$instance; }
public static function getInstance() { if (!isset(self::$instance)) { try { self::$instance = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASS); self::$instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); self::$instance->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ); } catch (PDOException $e) { echo $e->getMessage(); } } return self::$instance; }
public function remove($table) { return Connection::instance()->execute("DROP TABLE `{$table}`"); }
/** * Garbage collection. * * @param int $maxlifetime */ public function cleanup($maxlifetime) { $db = Connection::instance($this->dbLink); $verouderd = time() - $maxlifetime; if ($db->query('DELETE FROM ' . $db->quoteIdentifier($this->table) . ' WHERE last_used < ' . $db->quote($verouderd))) { return true; } return false; }
/** * @brief Constructeur de Manager. Récupère la connexion à la base de données * @return Void * @note Ne doit pas être overridé sinon la connexion à la base de données ne sera pas récupérée */ protected function __construct() { $this->bdd = Connection::instance()->getBdd(); }
public function __construct() { $pdo = Connection::instance(); $this->db = $pdo->dbConnect(); }
public static function instance($name) { $obj = Connection::instance($name); self::add($obj); return $obj; }
public function remove($table, $column) { return Connection::instance()->execute("ALTER TABLE `{$table}` DROP `{$column}`"); }
private function __destruct() { self::$instance = null; }