1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mattbit\MysqlCompat\BridgeComponents; |
4
|
|
|
|
5
|
|
|
use PDO; |
6
|
|
|
use Mattbit\MysqlCompat\Connection; |
7
|
|
|
use Mattbit\MysqlCompat\MysqlConstants; |
8
|
|
|
use Mattbit\MysqlCompat\Exception\NotSupportedException; |
9
|
|
|
|
10
|
|
|
trait ManageConnections |
11
|
|
|
{ |
12
|
|
|
public function clientEncoding(Connection $linkIdentifier = null) |
13
|
|
|
{ |
14
|
|
|
$connection = $this->manager->getOpenConnectionOrFail($linkIdentifier); |
15
|
|
|
|
16
|
|
|
return $connection->getCharset(); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function close(Connection $linkIdentifier = null) |
20
|
|
|
{ |
21
|
|
|
return $this->manager->disconnect($linkIdentifier); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function connect($server = null, $username = null, $password = null, $newLink = false, $clientFlags = 0) |
25
|
|
|
{ |
26
|
|
|
if ($server === null) { |
27
|
|
|
$server = ini_get('mysql.default_host'); |
28
|
|
|
} |
29
|
|
|
if ($username === null) { |
30
|
|
|
$username = ini_get('mysql.default_user'); |
31
|
|
|
} |
32
|
|
|
if ($password === null) { |
33
|
|
|
$password = ini_get('mysql.default_password'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
$options = $this->parseClientFlags($clientFlags); |
37
|
|
|
|
38
|
|
|
return $this->manager->connect("mysql:host={$server};", $username, $password, $options, $newLink); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
protected function parseClientFlags($clientFlags) |
42
|
|
|
{ |
43
|
|
|
$options = []; |
44
|
|
|
|
45
|
|
|
if ($clientFlags & MysqlConstants::CLIENT_COMPRESS) { |
46
|
|
|
$options[PDO::MYSQL_ATTR_COMPRESS] = 1; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
if ($clientFlags & MysqlConstants::CLIENT_IGNORE_SPACE) { |
50
|
|
|
$options[PDO::MYSQL_ATTR_IGNORE_SPACE] = 1; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
if ($clientFlags & MysqlConstants::CLIENT_SSL) { |
54
|
|
|
throw new NotSupportedException('SSL is not supported. You must create the PDO instance manually.'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
if ($clientFlags & MysqlConstants::CLIENT_INTERACTIVE) { |
58
|
|
|
throw new NotSupportedException('Interactive client is not supported by PDO.'); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return $options; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function pconnect() |
65
|
|
|
{ |
66
|
|
|
// @todo |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|