@@ 24-44 (lines=21) @@ | ||
21 | * |
|
22 | * @return \Pimf\Database |
|
23 | */ |
|
24 | public function connect(array $config) |
|
25 | { |
|
26 | $dsn = "mysql:host={$config['host']};dbname={$config['database']}"; |
|
27 | ||
28 | if (isset($config['port'])) { |
|
29 | $dsn .= ";port={$config['port']}"; |
|
30 | } |
|
31 | ||
32 | if (isset($config['unix_socket'])) { |
|
33 | $dsn .= ";unix_socket={$config['unix_socket']}"; |
|
34 | } |
|
35 | ||
36 | $connection = new \Pimf\Database($dsn, $config['username'], $config['password'], $this->options($config)); |
|
37 | ||
38 | // set to UTF-8 which should be fine for most scenarios. |
|
39 | if (isset($config['charset'])) { |
|
40 | $connection->prepare("SET NAMES '{$config['charset']}'")->execute(); |
|
41 | } |
|
42 | ||
43 | return $connection; |
|
44 | } |
|
45 | } |
|
46 |
@@ 31-52 (lines=22) @@ | ||
28 | * |
|
29 | * @return \Pimf\Database |
|
30 | */ |
|
31 | public function connect(array $config) |
|
32 | { |
|
33 | $dsn = "pgsql:host={$config['host']};dbname={$config['database']}"; |
|
34 | ||
35 | if (isset($config['port'])) { |
|
36 | $dsn .= ";port={$config['port']}"; |
|
37 | } |
|
38 | ||
39 | $connection = new \Pimf\Database($dsn, $config['username'], $config['password'], $this->options($config)); |
|
40 | ||
41 | // set to UTF-8 which should be fine for most scenarios. |
|
42 | if (isset($config['charset'])) { |
|
43 | $connection->prepare("SET NAMES '{$config['charset']}'")->execute(); |
|
44 | } |
|
45 | ||
46 | // If a schema has been specified |
|
47 | if (isset($config['schema'])) { |
|
48 | $connection->prepare("SET search_path TO '{$config['schema']}'")->execute(); |
|
49 | } |
|
50 | ||
51 | return $connection; |
|
52 | } |
|
53 | } |
|
54 |