Skip to content

Commit 934e655

Browse files
authored
Merge pull request #51 from skipperbent/v4-development
Version 4.2.0
2 parents cbc66cf + a849c99 commit 934e655

File tree

9 files changed

+281
-212
lines changed

9 files changed

+281
-212
lines changed

composer.lock

Lines changed: 24 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Pecee/Pixie/ConnectionAdapters/Exception.php

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/Pecee/Pixie/ConnectionAdapters/Mysql.php

Lines changed: 52 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,62 @@
33
namespace Pecee\Pixie\ConnectionAdapters;
44

55
use PDO;
6+
use Pecee\Pixie\Exception;
67

78
/**
89
* Class Mysql
910
*
1011
* @package Pecee\Pixie\ConnectionAdapters
1112
*/
12-
class Mysql extends BaseAdapter {
13-
/**
14-
* @param array $config
15-
*
16-
* @return PDO
17-
* @throws Exception
18-
*/
19-
protected function doConnect(array $config): PDO {
20-
if (\extension_loaded('pdo_mysql') === false) {
21-
throw new Exception(sprintf('%s library not loaded', 'pdo_mysql'));
22-
}
23-
24-
$connectionString = "mysql:dbname={$config['database']}";
25-
26-
if (isset($config['host']) === true) {
27-
$connectionString .= ";host={$config['host']}";
28-
}
29-
30-
if (isset($config['port']) === true) {
31-
$connectionString .= ";port={$config['port']}";
32-
}
33-
34-
if (isset($config['unix_socket']) === true) {
35-
$connectionString .= ";unix_socket={$config['unix_socket']}";
36-
}
37-
38-
$connection = new PDO($connectionString, $config['username'], $config['password'], $config['options']);
39-
40-
if (isset($config['charset'])) {
41-
$connection->prepare("SET NAMES '{$config['charset']}'")->execute();
42-
}
43-
44-
return $connection;
45-
}
46-
47-
/**
48-
* Get query adapter class
49-
* @return string
50-
*/
51-
public function getQueryAdapterClass(): string {
52-
return \Pecee\Pixie\QueryBuilder\Adapters\Mysql::class;
53-
}
13+
class Mysql extends BaseAdapter
14+
{
15+
/**
16+
* @param array $config
17+
*
18+
* @return PDO
19+
* @throws Exception
20+
*/
21+
protected function doConnect(array $config): PDO
22+
{
23+
if (\extension_loaded('pdo_mysql') === false) {
24+
throw new Exception(sprintf('%s library not loaded', 'pdo_mysql'));
25+
}
26+
27+
$connectionString = "mysql:dbname={$config['database']}";
28+
29+
if (isset($config['host']) === true) {
30+
$connectionString .= ";host={$config['host']}";
31+
}
32+
33+
if (isset($config['port']) === true) {
34+
$connectionString .= ";port={$config['port']}";
35+
}
36+
37+
if (isset($config['unix_socket']) === true) {
38+
$connectionString .= ";unix_socket={$config['unix_socket']}";
39+
}
40+
41+
try {
42+
43+
$connection = new PDO($connectionString, $config['username'], $config['password'], $config['options']);
44+
45+
if (isset($config['charset']) === true) {
46+
$connection->prepare("SET NAMES '{$config['charset']}'")->execute();
47+
}
48+
49+
} catch (\PDOException $e) {
50+
throw new Exception($e->getMessage(), $e->getCode());
51+
}
52+
53+
return $connection;
54+
}
55+
56+
/**
57+
* Get query adapter class
58+
* @return string
59+
*/
60+
public function getQueryAdapterClass(): string
61+
{
62+
return \Pecee\Pixie\QueryBuilder\Adapters\Mysql::class;
63+
}
5464
}

src/Pecee/Pixie/ConnectionAdapters/Pgsql.php

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,58 @@
33
namespace Pecee\Pixie\ConnectionAdapters;
44

55
use PDO;
6+
use Pecee\Pixie\Exception;
67

78
/**
89
* Class Pgsql
910
*
1011
* @package Pecee\Pixie\ConnectionAdapters
1112
*/
12-
class Pgsql extends BaseAdapter {
13-
/**
14-
* @param array $config
15-
*
16-
* @return PDO
17-
* @throws Exception
18-
*/
19-
protected function doConnect(array $config): PDO {
20-
if (\extension_loaded('pdo_pgsql') === false) {
21-
throw new Exception(sprintf('%s library not loaded', 'pdo_pgsql'));
22-
}
23-
24-
$connectionString = "pgsql:host={$config['host']};dbname={$config['database']}";
25-
26-
if (isset($config['port']) === true) {
27-
$connectionString .= ";port={$config['port']}";
28-
}
29-
30-
$connection = new PDO($connectionString, $config['username'], $config['password'], $config['options']);
31-
32-
if (isset($config['charset']) === true) {
33-
$connection->prepare("SET NAMES '{$config['charset']}'")->execute();
34-
}
35-
36-
if (isset($config['schema']) === true) {
37-
$connection->prepare("SET search_path TO '{$config['schema']}'")->execute();
38-
}
39-
40-
return $connection;
41-
}
42-
43-
/**
44-
* Get query adapter class
45-
* @return string
46-
*/
47-
public function getQueryAdapterClass(): string {
48-
return \Pecee\Pixie\QueryBuilder\Adapters\Pgsql::class;
49-
}
13+
class Pgsql extends BaseAdapter
14+
{
15+
/**
16+
* @param array $config
17+
*
18+
* @return PDO
19+
* @throws Exception
20+
*/
21+
protected function doConnect(array $config): PDO
22+
{
23+
if (\extension_loaded('pdo_pgsql') === false) {
24+
throw new Exception(sprintf('%s library not loaded', 'pdo_pgsql'));
25+
}
26+
27+
$connectionString = "pgsql:host={$config['host']};dbname={$config['database']}";
28+
29+
if (isset($config['port']) === true) {
30+
$connectionString .= ";port={$config['port']}";
31+
}
32+
33+
try {
34+
35+
$connection = new PDO($connectionString, $config['username'], $config['password'], $config['options']);
36+
37+
if (isset($config['charset']) === true) {
38+
$connection->prepare("SET NAMES '{$config['charset']}'")->execute();
39+
}
40+
41+
if (isset($config['schema']) === true) {
42+
$connection->prepare("SET search_path TO '{$config['schema']}'")->execute();
43+
}
44+
45+
} catch (\PDOException $e) {
46+
throw new Exception($e->getMessage(), $e->getCode());
47+
}
48+
49+
return $connection;
50+
}
51+
52+
/**
53+
* Get query adapter class
54+
* @return string
55+
*/
56+
public function getQueryAdapterClass(): string
57+
{
58+
return \Pecee\Pixie\QueryBuilder\Adapters\Pgsql::class;
59+
}
5060
}

0 commit comments

Comments
 (0)