src/Database/Drivers/ImprovedDriver.php
/**
	 * Connects to the database server.
	 *
	 * @throws DatabaseDriverException on error
	 */
Connects to the database server.
@throws DatabaseDriverException on error
Connects to the database server . @throws DatabaseDriverException on error
public function connect() {
		if ($this->connected) {
			return;
		}
		Profiler::start('database:connect', 'mysqli');
		$config = $this->database->getConfig();
		$port = isset($config['port']) ? (int)$config['port'] : 3306;
		$handle = @new mysqli($config['host'], $config['username'], $config['password'], $config['database'], $port);
		if ($handle->connect_error) {
			throw new DatabaseDriverException(sprintf('Failed to connect to database: %s', $handle->connect_error), $handle->connect_errno);
		}
		$this->handle = $handle;
		$this->connected = true;
		Profiler::start('database:connect:charset', $config['charset']);
		$this->handle->set_charset($config['charset']);
		$this->handle->query(sprintf('SET NAMES %s COLLATE %s;', $config['charset'], $config['collation']));
		if (config('database.send_timezone', true)) {
			$this->database->setTimezone();
		}
		Profiler::stop('database:connect:charset');
		Profiler::stop('database:connect');
	}
public function connect ( ) { if ( $ this -> connected ) { return ; } Profiler :: start ( 'database:connect' , 'mysqli' ) ; $ config = $ this -> database -> getConfig ( ) ; $ port = isset ( $ config [ 'port' ] ) ? ( int ) $ config [ 'port' ] : 3306 ; $ handle = @ new mysqli ( $ config [ 'host' ] , $ config [ 'username' ] , $ config [ 'password' ] , $ config [ 'database' ] , $ port ) ; if ( $ handle -> connect_error ) { throw new DatabaseDriverException ( sprintf ( 'Failed to connect to database: %s' , $ handle -> connect_error ) , $ handle -> connect_errno ) ; } $ this -> handle = $ handle ; $ this -> connected = true ; Profiler :: start ( 'database:connect:charset' , $ config [ 'charset' ] ) ; $ this -> handle -> set_charset ( $ config [ 'charset' ] ) ; $ this -> handle -> query ( sprintf ( 'SET NAMES %s COLLATE %s;' , $ config [ 'charset' ] , $ config [ 'collation' ] ) ) ; if ( config ( 'database.send_timezone' , true ) ) { $ this -> database -> setTimezone ( ) ; } Profiler :: stop ( 'database:connect:charset' ) ; Profiler :: stop ( 'database:connect' ) ; }
Connects to the database server.
Connects to the database server .
// Save the handle and status // Set the charset and collation