1: <?php namespace Laravel\Database\Connectors; use PDO;
2:
3: class Postgres extends Connector {
4:
5: 6: 7: 8: 9:
10: protected $options = array(
11: PDO::ATTR_CASE => PDO::CASE_LOWER,
12: PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
13: PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL,
14: PDO::ATTR_STRINGIFY_FETCHES => false,
15: );
16:
17: 18: 19: 20: 21: 22:
23: public function connect($config)
24: {
25: extract($config);
26:
27: $host_dsn = isset($host) ? 'host='.$host.';' : '';
28:
29: $dsn = "pgsql:{$host_dsn}dbname={$database}";
30:
31:
32:
33:
34: if (isset($config['port']))
35: {
36: $dsn .= ";port={$config['port']}";
37: }
38:
39: $connection = new PDO($dsn, $username, $password, $this->options($config));
40:
41:
42:
43:
44: if (isset($config['charset']))
45: {
46: $connection->prepare("SET NAMES '{$config['charset']}'")->execute();
47: }
48:
49:
50:
51: if (isset($config['schema']))
52: {
53: $connection->prepare("SET search_path TO {$config['schema']}")->execute();
54: }
55:
56: return $connection;
57: }
58:
59: }