|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Class PDOFirebirdDriver |
|
4
|
|
|
* |
|
5
|
|
|
* @filesource PDOFirebirdDriver.php |
|
6
|
|
|
* @created 04.11.2015 |
|
7
|
|
|
* @package chillerlan\Database\Drivers\PDO |
|
8
|
|
|
* @author Smiley <[email protected]> |
|
9
|
|
|
* @copyright 2015 Smiley |
|
10
|
|
|
* @license MIT |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace chillerlan\Database\Drivers\PDO; |
|
14
|
|
|
|
|
15
|
|
|
use chillerlan\Database\DBException; |
|
16
|
|
|
use chillerlan\Database\Drivers\DBDriverInterface; |
|
17
|
|
|
use PDO; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @todo: STRTOLOWER COLUMN NAMES |
|
21
|
|
|
*/ |
|
22
|
|
|
class PDOFirebirdDriver extends PDODriverAbstract{ |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* The PDO drivername which is being used in the DSN |
|
26
|
|
|
* |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $drivername = 'firebird'; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Returns a DSN string using the given options |
|
33
|
|
|
* @see http://php.net/manual/en/ref.pdo-firebird.connection.php |
|
34
|
|
|
* |
|
35
|
|
|
* @return string DSN |
|
36
|
|
|
*/ |
|
37
|
|
|
protected function getDSN():string { |
|
38
|
|
|
$dsn = $this->drivername.':dbname='; |
|
39
|
|
|
|
|
40
|
|
|
if(!empty($this->options->host)){ |
|
41
|
|
|
$dsn .= $this->options->host; |
|
42
|
|
|
|
|
43
|
|
|
if(is_numeric($this->options->port)){ |
|
44
|
|
|
$dsn .= '/'.$this->options->port; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
$dsn .= ':'; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$dsn .= $this->options->database; |
|
51
|
|
|
|
|
52
|
|
|
return $dsn; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Establishes a database connection and returns the connection object |
|
57
|
|
|
* |
|
58
|
|
|
* @return \chillerlan\Database\Drivers\DBDriverInterface |
|
59
|
|
|
* @throws \chillerlan\Database\DBException |
|
60
|
|
|
*/ |
|
61
|
|
|
public function connect():DBDriverInterface{ |
|
62
|
|
|
|
|
63
|
|
|
if($this->db instanceof PDO){ |
|
64
|
|
|
return $this; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
try{ |
|
68
|
|
|
|
|
69
|
|
|
if(!is_file($this->options->database)){ |
|
70
|
|
|
trigger_error('file not found'); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$this->db = new PDO($this->getDSN(), $this->options->username, $this->options->password, $this->pdo_options); |
|
74
|
|
|
|
|
75
|
|
|
return $this; |
|
76
|
|
|
} |
|
77
|
|
|
catch(\Exception $e){ |
|
78
|
|
|
throw new DBException('db error: [PDOFirebirdDriver]: '.$e->getMessage()); // @codeCoverageIgnore |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Returns the last insert id (if present) |
|
84
|
|
|
* |
|
85
|
|
|
* Firebird -> SQLSTATE[IM001]: driver does not support lastInsertId() |
|
86
|
|
|
* |
|
87
|
|
|
* @link http://php.net/manual/pdo.lastinsertid.php |
|
88
|
|
|
* @return string |
|
89
|
|
|
* @codeCoverageIgnore |
|
90
|
|
|
*/ |
|
91
|
|
|
protected function insertID():string { |
|
92
|
|
|
return ''; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
} |
|
96
|
|
|
|