1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| class DB
{
private $config;
public function __construct()
{
$json = file_get_contents(__DIR__ . 'monfichier.json');
$json = json_decode($json, true);
$this->config = $json;
}
public function getExample()
{
$dsn = $this->config['one']['dsn'];
$username = $this->config['one']['username'];
$password = $this->config['one']['password'];
$conn = new \PDO($dsn, $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $conn;
}
public function getOtherExample($clientId)
{
$dsn = $this->config[other]['dsn'];
$username = $this->config[other]['username'];
$password = $this->config[$other]['password'];
$conn = new \PDO($dsn, $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $conn;
}
} |
Partager