public static function Close() { $error = mysql_error(Database::$link); if ($error) { die("Q" . Database::$curQueryNum . ": Invalid Query: " . mysql_error(Database::$link)); } mysql_close(Database::$link); Database::$link = null; }
private static function connect() { if (null !== self::$link) { return; } self::load_config(); self::$link = new mysqli(self::$config['HOST'], self::$config['USER'], self::$config['PASSWORD'], self::$config['DATABASE']); if (self::$link->connect_errno) { self::$link = null; return; } self::$link->set_charset('utf8'); }
public static function connect($host, $user, $pwd, $dbname, $pconnect = false) { self::$link = $pconnect ? @mysql_pconnect($host, $user, $pwd) : @mysql_connect($host, $user, $pwd); if (!self::$link) { self::halt("Can't connect to database!"); } if (!mysql_select_db($dbname, self::$link)) { self::halt("Can't use database {$dbname}!"); } if (self::version() > '4.1') { mysql_query('SET NAMES utf8;', self::$link); } }
private static function getLink() { // Return $link variable if its defined if (self::$link) { return self::$link; } // Parse the .ini file for the db information $info = parse_ini_file(dirname(__FILE__) . '/../config.ini', true); // Set up the Data Source Name, which contains the info for // the DB connection $dsn = "{$info['driver']}:"; foreach ($info['dsn'] as $key => $value) { $dsn .= "{$key}={$value};"; } // Actually connect self::$link = new PDO($dsn, $info['user'], $info['pass']); self::$link->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); return self::$link; }
public static function connect() { self::$link = mysqli_connect(DBhost, DBuser, DBpass, DBname); }
public static function init() { self::$link = mysql_connect(self::$server, self::$username, self::$password); mysql_set_charset('utf8'); mysql_select_db(self::$database); }
public static function connect($host, $db, $user, $password) { $link = @mysql_connect($host, $user, $password); if (!$link) { return 'Could not connect to host: ' . mysql_error(); } if (!@mysql_select_db($db, $link)) { return 'Could not select database: ' . mysql_error(); } self::$link = $link; return true; }