/** * connector * * there will be only one connection instance * * @param array $args * @param string $user * @param string $password * @return PDB_mysqli */ protected static function connect($args, $user = false, $password = false) { if (!isset(self::$_instance)) { $c = __CLASS__; self::$_instance = new $c(); if (PVars::get()->debug) { $t = microtime(); PSurveillance::setPoint('connect' . $t); } if (!isset($args['host'])) { throw new PException('Host not set!'); } if (!isset($args['dbname'])) { throw new PException('DB name not set!'); } $mysqli = @new mysqli($args['host'], $user, $password, $args['dbname']); if (!$mysqli || mysqli_connect_errno()) { $E = new PException('Could not connect!'); $E->addInfo(mysqli_connect_error()); throw $E; } self::$_instance->_MySQLi = $mysqli; self::$_instance->_dbname = $args['dbname']; $queries = array("SET NAMES 'utf8'", "SET CHARACTER SET 'utf8'", "SET collation_connection='utf8_general_ci'"); foreach ($queries as $query) { $q = self::$_instance->exec($query); if (!$q) { throw new PException('MySQL collation error!', 1000); } } if (PVars::get()->debug) { PSurveillance::setPoint('eoconnect' . $t); } } return self::$_instance; }