private function __construct() { # Informações sobre o banco de dados: $db_host = "localhost"; $db_nome = "blog"; $db_usuario = "root"; $db_senha = "root"; $db_driver = "mysql"; # Informações sobre o sistema: $sistema_titulo = "Nome do Sistema"; $sistema_email = "*****@*****.**"; try { # Atribui o objeto PDO à variável $db. self::$db = new PDO("{$db_driver}:host={$db_host}; dbname={$db_nome}", $db_usuario, $db_senha); # Garante que o PDO lance exceções durante erros. self::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); # Garante que os dados sejam armazenados com codificação UFT-8. self::$db->exec('SET NAMES utf8'); } catch (PDOException $e) { # Envia um e-mail para o e-mail oficial do sistema, em caso de erro de conexão. mail($sistema_email, "PDOException em {$sistema_titulo}", $e->getMessage()); # Então não carrega nada mais da página. die("Connection Error: " . $e->getMessage()); } }
public static function getConnection() { if (self::$db == null) { self::$db = new Database(); } return self::$db->connection; }
public static function getDatabase() { if (Database::$db === FALSE) { Database::$db = new Database(); } return Database::$db; }
/** * @param $db * @param $dbs */ public function setConnection($db, $dbs = array()) { self::$db = $db; // Using read/write connections see the services.php file self::$connectionRead = isset($dbs['db_read']) ? $dbs['db_read'] : $db; self::$connectionWrite = isset($dbs['db_write']) ? $dbs['db_write'] : $db; }
protected static function setUpConnection() { if (!isset(self::$db)) { $dbType = 'Zend_Db_Adapter_Pdo_' . self::$dbType; self::$db = new $dbType(array('host' => self::$dbHost, 'username' => self::$dbUsername, 'password' => self::$dbPassword, 'dbname' => self::$dbName)); } }
public static function get_instance() { if (!isset(self::$db)) { self::$db = new Database(); } return self::$db; }
public static function GetInstance() { if (!isset(self::$db)) { self::$db = new static(); } return self::$db; }
public static function getInstance() { if (self::$db === null) { self::$db = new self(); } return self::$db; }
private function __construct() { # Informações sobre o banco de dados: $db_host = "localhost"; $db_nome = "teste_pdo"; $db_usuario = "root"; $db_senha = ""; $db_driver = "mysql"; # Informações sobre o sistema: $sistema_titulo = "Nome do Sistema"; $sistema_email = "*****@*****.**"; try { # Atribui o objeto PDO à variável $db. self::$db = new PDO("{$db_driver}:host={$db_host}; dbname={$db_nome}", $db_usuario, $db_senha); # Garante que o PDO lance exceções durante erros. self::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); # Garante que os dados sejam armazenados com codificação UFT-8. self::$db->exec('SET NAMES utf8'); } catch (PDOException $e) { # Envia um e-mail para o e-mail oficial do sistema, em caso de erro de conexão. mail($sistema_email, "PDOException em {$sistema_titulo}", $e->getMessage()); # Então não carrega nada mais da página. //die("Connection Error: " . $e->getMessage()); print "Ocorreu um erro ao tentar executar esta ação, foi gerado\r\n um LOG do mesmo, tente novamente mais tarde."; GeraLog::getInstance()->inserirLog("Erro: Código: " . $e->getCode() . " Mensagem: " . $e->getMessage()); exit; } }
public static function getConnection() { if (!self::$db) { self::$db = new PDO('mysql:host=localhost;dbname=users', 'root', '12345'); } return self::$db; }
/** * Returns database connection handler. */ public static function get_connection() { if (!isset(self::$db)) { global $config; self::$db = new PDO("mysql:host={$config['db']['host']};dbname={$config['db']['database']}", $config['db']['username'], $config['db']['password']); } return self::$db; }
public static function setup($db_type = "pgsql", $host = "ec2-54-83-204-228.compute-1.amazonaws.com", $db_name = "d31sdik2uip6li", $username = "******", $password = "******") { if (!isset(self::$db)) { self::$db = R::setup($db_type . ":host=" . $host . "; dbname=" . $db_name, $username, $password); R::freeze(); } return self::$db; }
public static function getDatabase() { if (Database::$db === FALSE) { Database::$db = new Database(); Database::$db->exec("SET CHARACTER SET utf8"); } return Database::$db; }
/** * Get the database singleton * @return The one PDO instance */ public static function getDB() { if (self::$db == null) { self::$db = new PDO('mysql:host=' . self::$host . ';dbname=' . self::$dbname, self::$username, self::$password); self::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } return self::$db; }
static function DB() { if (empty(self::$db)) { include_once __DIR__ . '/databaseDrivers/' . Settings::$DB_DRIVER . '.php'; self::$db = new Settings::$DB_DRIVER(Settings::$DB_host, Settings::$DB_username, Settings::$DB_password, Settings::$DB_name); } return self::$db; }
public static function getConnection() { if (isset(self::$db)) { return self::$db; } else { self::$db = self::connect(); return self::$db; } }
public static function init($connectString, $username, $password) { try { self::$db = new PDO($connectString, $username, $password); self::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (Exception $e) { throw new Exception('Could not connect to database'); } }
public static function getConnection() { $connectionInfo = array("UID" => DBSettings::$dbUser, "PWD" => DBSettings::$dbPass, "Database" => DBSettings::$database, "ReturnDatesAsStrings" => true); if (!self::$db) { self::$db = sqlsrv_connect(DBSettings::$Server, $connectionInfo); // Creates and opens a connection. } return self::$db; }
/** * Get the PDO object, initializing it if necessary * * @return PDO */ public static function pdo() { // check & see if the connection is already open if (!Database::$db) { Database::$db = new PDO(Config::get('database.dsn')); Database::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } return Database::$db; }
public static function init() { try { self::$db = new PDO(self::DB_CONNECT_STRING, self::DB_USERNAME, self::DB_PASSWORD); self::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (Exception $e) { throw new Exception('Could not connect to database'); } }
public static function init_connection($host, $db, $table, $username, $password) { self::$host = $host; self::$db = $db; self::$table = $table; self::$user = $username; self::$password = $password; self::$mysqli = new mysqli(self::$host, self::$user, self::$password, self::$db); return self::$mysqli->ping(); }
public static function connect() { if (Database::$db == null) { $host = Setting::getFromFile("host"); $user = Setting::getFromFile("user"); $pass = Setting::getFromFile("pass"); $database = Setting::getFromFile("database"); Database::$db = @mysqli_connect($host == null ? "" : $host, $user == null ? "" : $user, $pass == null ? "" : $pass, $database == null ? "" : $database); } return Database::$db; }
private function __construct() { try { $app = App::get_instance(); self::$db = new PDO('mysql:host=' . $app['db']['server'] . ';dbname=' . $app['db']['database'], $app['db']['username'], $app['db']['password']); self::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); self::$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); } catch (PDOException $e) { echo "Database error: " . $e->getMessage(); } }
public static function getDB() { try { self::$db = new PDO(self::$dsn, self::$username, self::$password); return self::$db; } catch (PDOException $e) { $error_message = $e->getMessage(); include '../errors/database_error.php'; exit; } }
public static function getInstance() { // if we haven't instantiate any db, instantiate one try { if (self::$db === NULL) { self::$db = new PDO("mysql:host=" . DB_HOST . ";dbname=" . DB_NAME, DB_USER, DB_PASSWORD); } return self::$db; } catch (PDOException $e) { echo $e->getMessage(); } }
public static function getDB() { if (!isset(self::$db)) { try { self::$db = new PDO(self::$dsn, self::$username, self::$password); } catch (PDOException $e) { self::display_db_error($e->getMessage()); die; } } return self::$db; }
public static function getInstance() { if (self::$db === NULL) { try { self::$db = new PDO(DB_DRIVER . ':host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USERNAME, DB_PASSWORD, array(PDO::ATTR_PERSISTENT => true)); } catch (PDOException $e) { echo 'Error!: ' . $e->getMessage(); die; } } return self::$db; }
public function __construct() { try { $Dbconfig = new Dbconfig(); $Parametros = $Dbconfig->ObterParametros(); self::$db = new PDO($Parametros[0] . ":host=" . $Parametros[1] . ";dbname=" . $Parametros[2], $Parametros[3], $Parametros[4]); self::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); self::$db->exec('SET NAMES utf8'); } catch (PDOException $e) { die("Erro na Conexao com banco, mensagem de erro : " . $e->getMessage()); } }
public static function &getDB() { if (Database::$db == null) { Database::$db = new PDO(PDO_CONN_DSN, PDO_CONN_USER, PDO_CONN_PASS); if (Database::$db == null) { die("ERROR!"); } Database::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); Database::$db->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('PDOStatementCaching', array())); } return Database::$db; }
public static function getDB() { if (!isset(self::$db)) { try { self::$db = new PDO(self::$dsn, self::$username, self::$password); } catch (PDOException $e) { $error_message = $e->getMessage(); include "../Errors/DatabaseError.php"; exit; } } return self::$db; }