Skip to content

Instantly share code, notes, and snippets.

@kobus1998
Created January 19, 2018 09:02
Show Gist options
  • Save kobus1998/9447c33df10f48a3df88a61fcaef6a3d to your computer and use it in GitHub Desktop.
Save kobus1998/9447c33df10f48a3df88a61fcaef6a3d to your computer and use it in GitHub Desktop.
<?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