Created
January 19, 2018 09:02
-
-
Save kobus1998/9447c33df10f48a3df88a61fcaef6a3d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
private function pdo (): \PDO | |
{ | |
return new \PDO(" | |
mysql:host={$this->config['host']}; | |
port={$this->config['port']}; | |
dbname={$this->config['dbname']}", | |
$this->config['user'], | |
$this->config['pass']); | |
} | |
public function connect () | |
{ | |
try { | |
$pdo = $this->pdo(); | |
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); | |
$this->connection = $pdo; | |
} catch (PDOException $e) { | |
echo 'Connection failed: ' . $e->getMessage(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment