1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Class FirebirdPDO |
4
|
|
|
* |
5
|
|
|
* @filesource FirebirdPDO.php |
6
|
|
|
* @created 28.06.2017 |
7
|
|
|
* @package chillerlan\Database\Drivers |
8
|
|
|
* @author Smiley <[email protected]> |
9
|
|
|
* @copyright 2017 Smiley |
10
|
|
|
* @license MIT |
11
|
|
|
* |
12
|
|
|
* @noinspection PhpComposerExtensionStubsInspection |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace chillerlan\Database\Drivers; |
16
|
|
|
|
17
|
|
|
use chillerlan\Database\Dialects\Firebird; |
18
|
|
|
use Exception, PDO; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @property \PDO $db |
22
|
|
|
*/ |
23
|
|
|
class FirebirdPDO extends PDODriverAbstract{ |
24
|
|
|
|
25
|
|
|
protected string $drivername = 'firebird'; |
26
|
|
|
protected string $dialect = Firebird::class; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @inheritdoc |
30
|
|
|
* |
31
|
|
|
* @link http://php.net/manual/ref.pdo-firebird.connection.php |
32
|
|
|
*/ |
33
|
|
|
protected function getDSN():string { |
34
|
|
|
$dsn = $this->drivername.':dbname='; |
35
|
|
|
|
36
|
|
|
if($this->options->host !== null){ |
37
|
|
|
$dsn .= $this->options->host; |
38
|
|
|
|
39
|
|
|
if(is_numeric($this->options->port)){ |
40
|
|
|
$dsn .= '/'.$this->options->port; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$dsn .= ':'; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
$dsn .= $this->options->database; |
47
|
|
|
|
48
|
|
|
if($this->options->firebird_encoding !== null){ |
49
|
|
|
$dsn .= ';encoding='.$this->options->firebird_encoding; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return $dsn; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** @inheritdoc */ |
56
|
|
|
public function connect():DriverInterface{ |
57
|
|
|
|
58
|
|
|
if($this->db instanceof PDO){ |
|
|
|
|
59
|
|
|
return $this; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
try{ |
63
|
|
|
|
64
|
|
|
if(!is_file($this->options->database)){ |
65
|
|
|
trigger_error('file not found'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$this->db = new PDO($this->getDSN(), $this->options->username, $this->options->password, $this->pdo_options); |
69
|
|
|
|
70
|
|
|
return $this; |
71
|
|
|
} |
72
|
|
|
catch(Exception $e){ |
73
|
|
|
throw new DriverException('db error: [FirebirdPDO]: '.$e->getMessage()); // @codeCoverageIgnore |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @inheritdoc |
80
|
|
|
* |
81
|
|
|
* @codeCoverageIgnore Firebird -> SQLSTATE[IM001]: driver does not support lastInsertId() |
82
|
|
|
*/ |
83
|
|
|
protected function insertID():string { |
84
|
|
|
return ''; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** @inheritdoc */ |
88
|
|
|
public function getServerInfo():?string{ |
89
|
|
|
return $this->db->getAttribute(PDO::ATTR_SERVER_INFO).', connected to: '.$this->options->database; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
} |
93
|
|
|
|