protected static function getConnection() { if (!self::$connection) { self::$connection = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASSWORD, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]); } return self::$connection; }
public static function getInstance() { if (!self::$connection) { self::$connection = new self(); } return self::$connection; }
public function getTermInfo($condition) { $db = Db::connection($this->connection)->table($this->table); $db = $this->formatCondition($db, $condition); $res = $db->first(); return $res; }
public static function connect($host, $database, $user, $password) { if (!isset(self::$connection)) { $dsn = "mysql:host={$host};dbname={$database}"; self::$connection = new PDO($dsn, $user, $password, self::$options); } }
public static function connect($config) { self::$connection = @new mysqli($config['hostname'], $config['username'], $config['password'], $config['database']); if (self::$connection->connect_errno) { throw new Exception(self::$connection->connect_error); } self::execute("SET NAMES 'utf8'"); }
public static function connect($host, $user, $password, $database) { if (!isset(self::$connection)) { self::$connection = @new PDO("mysql:host={$host};dbname={$database}", $user, $password, self::$settings); return true; } return false; }
public function connect() { if (!isset(self::$connection)) { self::$connection = new mysqli('localhost', "root", "", "gotit"); } if (self::$connection === false) { return false; } return self::$connection; }
/** * Connect to the database * * @return bool false on failure / mysqli MySQLi object instance on success */ public function connect() { if (!isset(self::$connection)) { $config = parse_ini_file('../config/config.ini'); self::$connection = new mysqli($config['host'], $config['username'], $config['password'], $config['dbname']); } if (self::$connection === false) { return false; } return self::$connection; }
public function connect() { if (!isset(self::$connection)) { $login = $this->readLogin("../../config.json"); self::$connection = new mysqli($login["hostname"], $login["username"], $login["password"], $login["db"]); } if (self::$connection->connect_errno) { echo "Failed to connect to MySQL: " . self::$connection->connect_error; return false; } return self::$connection; }
/** * Connect to database. */ public static function connect() { self::$connection = mysql_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD); if (!self::$connection) { trigger_error('Can\'t connect to database.'); return false; } else { mysql_select_db(DB_DATABASE); mysql_query("SET CHARACTER SET " . MYSQL_CHARSET); return true; } }
/** * Connect to the database * * @return bool false on failure / mysqli MySQLi object instance on success */ public function connect() { // Try and connect to the database if (!isset(self::$connection)) { self::$connection = new mysqli(global_mysql_server, global_mysql_user, global_mysql_password, global_mysql_database); } // If connection was not successful, handle the error if (self::$connection === false) { // Handle error - notify administrator, log to a file, show an error screen, etc. return false; } return self::$connection; }
public function connect() { if (!isset(self::$connection)) { self::$connection = new mysqli(\DbConfig::HOST, \DbConfig::USER_NAME, \DbConfig::USER_PASSWORD, \DbConfig::DB_NAME); } //If connection was not success, handle the error if (!self::$connection) { // Handle error - notify administrator, log to a file, show an error screen, etc. return false; } self::$connection->autocommit(false); return self::$connection; }
/** * Connect to the database * * @return bool false on failure / mysqli MySQLi object instance on success */ public function connect() { // Try and connect to the database if (!isset(self::$connection)) { // Load configuration as an array. Use the actual location of your configuration file self::$connection = new mysqli('localhost', 'root', 'root', 'servicioslegales'); } // If connection was not successful, handle the error if (self::$connection === false) { // Handle error - notify administrator, log to a file, show an error screen, etc. return false; } return self::$connection; }
/** * Connect to the database * * @return bool false on failure / mysqli MySQLi object instance on success */ public function connect() { // Try and connect to the database if (!isset(self::$connection)) { // Load configuration as an array. Use the actual location of your configuration file // Put the configuration file outside of the document root self::$connection = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME); } // If connection was not successful, handle the error if (self::$connection === false) { // Handle error - notify administrator, log to a file, show an error screen, etc. return false; } return self::$connection; }
public function connect() { // Try and connect to the database, if a connection has not been established yet if (!isset(self::$connection)) { // Load configuration self::$connection = mysqli_connect(host, user, pass, dbname) or die("no connection"); mysqli_select_db(self::$connection, 'moviefy'); } // If connection was not successful, handle the error if (self::$connection === false) { //Handle Error - notify admin return mysqli_connect_error($connection); } return self::$connection; }
/** * Connect to the database * * @return bool false on failure / mysqli MySQLi object instance on success */ public function connect() { // Try and connect to the database if (!isset(self::$connection)) { // Load configuration as an array. Use the actual location of your configuration file $config = parse_ini_file('../config/config.ini'); self::$connection = new mysqli('localhost', $config['username'], $config['password'], $config['dbname']); } // If connection was not successful, handle the error if (self::$connection === false) { // Handle error - notify administrator, log to a file, show an error screen, etc. return false; } return self::$connection; }
public static function connect() { //try and connect to database if (!isset(self::$connection)) { //load configuration as an array global $config; self::$connection = new mysqli($config['host'], $config['username'], $config['password'], $config['db']); } //if connection was not successful, handle the error if (self::$connection === false) { // Handle error - notify administrator, log to a file, show an error screen, etc. return false; } return self::$connection; }
/** * Connect to the database * * @return bool false on failure / mysqli MySQLi object instance on success */ public function connect() { // Try and connect to the database if (!isset(self::$connection)) { // get database settings $root = realpath($_SERVER["DOCUMENT_ROOT"]); include "{$root}/dbsettings/dbsettings.php"; self::$connection = new mysqli($sql_details['host'], $sql_details['user'], $sql_details['pass'], $sql_details['db']); } // If connection was not successful, handle the error if (self::$connection === false) { // Handle error - notify administrator, log to a file, show an error screen, etc. return false; } return self::$connection; }
public static function pdoConnect() { global $server; global $username; global $password; global $database; try { if (!self::$hasConnection) { self::$connection = new PDO("mysql:host={$server};dbname=" . $database, $username, $password); self::$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); self::$hasConnection = true; } return self::$connection; } catch (PDOException $e) { echo "Connection failed: " . $e->getMessage(); } }
/** * Connect to the database * * @return bool false on failure / mysqli MySQLi object instance on success */ public static function connect() { // Try and connect to the database if (!isset(self::$connection)) { echo "New connection<br>"; // Load configuration as an array. Use the actual location of your configuration file //$config = parse_ini_file('./config.ini'); //self::$connection = new mysqli('localhost',$config['username'],$config['password'],$config['dbname']); self::$connection = new mysqli("localhost", "kano", "kano", "kano"); } // If connection was not successful, handle the error if (self::$connection === false) { // Handle error - notify administrator, log to a file, show an error screen, etc. die("Connection failed: " . $connection->connect_error); return false; } return self::$connection; }
/** * Connect to the database * * @return bool false on failure / mysqli MySQLi object instance on success */ public function connect() { if (!isset(self::$connection)) { if (session_status() == PHP_SESSION_NONE) { session_start(); } if (!isset($_SESSION['host']) or !isset($_SESSION['username']) or !isset($_SESSION['password']) or !isset($_SESSION['dbname'])) { die("db.class: can't get database connection info from session"); } else { self::$connection = new mysqli($_SESSION['host'], $_SESSION['username'], $_SESSION['password'], $_SESSION['dbname']); } } if (self::$connection === false) { die('"db.class: Unable to connect to database'); return false; } return self::$connection; }
public function connect() { $_host = DATABASE_HOSTNAME; $_username = DATABASE_USERNAME; $_password = DATABASE_PASSWORD; $_database = DATABASE_DATABASE; // Try and connect to the database if (!isset(self::$connection)) { // Load configuration as an array. Use the actual location of your configuration file // Put the configuration file outside of the document root self::$connection = new mysqli($_host, $_username, $_password, $_database); } // If connection was not successful, handle the error if (self::$connection === false) { // Handle error - notify administrator, log to a file, show an error screen, etc. return false; } return self::$connection; }
public static function __shutdown__() { if (self::$ftmp !== null && is_dir(self::ftpath())) { foreach (File::dirs(self::ftpath()) as $dir) { File::rm($dir); } } if (!empty(self::$TMP_DB)) { foreach (self::$TMP_DB as $db => $table) { $dobj = Db::connection($db); foreach ($table as $name => $value) { $dobj->drop_table($name); $dobj->commit(); } } } }
public function close() { self::$connection = null; }
public static function connect($db_host, $db_name, $username, $password) { if (!isset(self::$connection)) { self::$connection = new PDO('mysql:host=' . $db_host . ';dbname=' . $db_name, $username, $password, self::$config); } }
public function testPassGetter() { $this->assertInstanceOf('MongoCollection', Db::connection()->test); }
protected final function get_connection() { if (!isset(self::$CONNECTION[$this->_class_])) { self::$CONNECTION[$this->_class_] = Db::connection($this->_database_); } if (empty($this->_table_)) { $this->_table_ = strtolower($this->_class_[0]); for ($i = 1; $i < strlen($this->_class_); $i++) { $this->_table_ .= ctype_lower($this->_class_[$i]) ? $this->_class_[$i] : "_" . strtolower($this->_class_[$i]); } } $this->_table_ = $this->set_table_name($this->_table_); $dbtype = $this->connection()->type(); $this->add_modules(new $dbtype()); }