src/Database/Drivers/PdoDriver.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', 'pdo');
		try {
			$config = $this->database->getConfig();
			$port = isset($config['port']) ? (int)$config['port'] : 3306;
			$handle = new PDO(
				sprintf(
					'mysql:host=%s;port=%s;dbname=%s;charset=%s',
					$config['host'],
					$port,
					$config['database'],
					$config['charset']
				),
				$config['username'],
				$config['password']
			);
			$handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
		}
		catch (PDOException $e) {
			$message = $e->getMessage();
			while ($pos = strpos($message, '] ')) {
				$message = trim(substr($message, $pos + 1));
			}
			throw new DatabaseDriverException(sprintf('Failed to connect to database: %s', $message), $e->getCode());
		}
		$this->handle = $handle;
		$this->connected = true;
		$this->handle->exec(sprintf('SET NAMES %s COLLATE %s;', $config['charset'], $config['collation']));
		if (config('database.send_timezone', true)) {
			$this->database->setTimezone();
		}
		Profiler::stop('database:connect');
	}
public function connect ( ) { if ( $ this -> connected ) { return ; } Profiler :: start ( 'database:connect' , 'pdo' ) ; try { $ config = $ this -> database -> getConfig ( ) ; $ port = isset ( $ config [ 'port' ] ) ? ( int ) $ config [ 'port' ] : 3306 ; $ handle = new PDO ( sprintf ( 'mysql:host=%s;port=%s;dbname=%s;charset=%s' , $ config [ 'host' ] , $ port , $ config [ 'database' ] , $ config [ 'charset' ] ) , $ config [ 'username' ] , $ config [ 'password' ] ) ; $ handle -> setAttribute ( PDO :: ATTR_ERRMODE , PDO :: ERRMODE_EXCEPTION ) ; } catch ( PDOException $ e ) { $ message = $ e -> getMessage ( ) ; while ( $ pos = strpos ( $ message , '] ' ) ) { $ message = trim ( substr ( $ message , $ pos + 1 ) ) ; } throw new DatabaseDriverException ( sprintf ( 'Failed to connect to database: %s' , $ message ) , $ e -> getCode ( ) ) ; } $ this -> handle = $ handle ; $ this -> connected = true ; $ this -> handle -> exec ( sprintf ( 'SET NAMES %s COLLATE %s;' , $ config [ 'charset' ] , $ config [ 'collation' ] ) ) ; if ( config ( 'database.send_timezone' , true ) ) { $ this -> database -> setTimezone ( ) ; } Profiler :: stop ( 'database:connect' ) ; }
Connects to the database server.
Connects to the database server .
// Save the handle and status // Set the charset and collation // Set the timezone