1 | <?php |
||
26 | abstract class AbstractDatabase { |
||
27 | |||
28 | /** |
||
29 | * Authenticator. |
||
30 | * |
||
31 | * @var Authenticator |
||
32 | */ |
||
33 | private $authenticator; |
||
34 | |||
35 | /** |
||
36 | * Connection. |
||
37 | * |
||
38 | * @var PDO |
||
39 | */ |
||
40 | private $connection; |
||
41 | |||
42 | /** |
||
43 | * Database. |
||
44 | * |
||
45 | * @var string |
||
46 | */ |
||
47 | private $database; |
||
48 | |||
49 | /** |
||
50 | * Constructor. |
||
51 | */ |
||
52 | protected function __construct(Authenticator $authenticator) { |
||
55 | |||
56 | /** |
||
57 | * Connect. |
||
58 | * |
||
59 | * @return PDO Returns the connection. |
||
60 | * @throws Exception Throws an exception if the connection failed. |
||
61 | */ |
||
62 | abstract protected function connect(); |
||
63 | |||
64 | /** |
||
65 | * Execute a script. |
||
66 | * |
||
67 | * @param string $scriptname The script name. |
||
68 | * @param boolean $output Output ? |
||
69 | * @return array Returns an array with success, failed and total queries. |
||
70 | * @throws FileNotFoundException Throws a file not found exception if the script name does not exists. |
||
71 | */ |
||
72 | final public function executeScript($scriptname, $output = false) { |
||
116 | |||
117 | /** |
||
118 | * Get the authenticator. |
||
119 | * |
||
120 | * @return Authenticator Returns the authenticator. |
||
121 | */ |
||
122 | final public function getAuthenticator() { |
||
125 | |||
126 | /** |
||
127 | * Get the connection. |
||
128 | * |
||
129 | * @return PDO Returns the connection. |
||
130 | * @throws Exception Throws an exception if the connection failed. |
||
131 | */ |
||
132 | final public function getConnection() { |
||
138 | |||
139 | /** |
||
140 | * Get the database. |
||
141 | * |
||
142 | * @return string Returns the database. |
||
143 | */ |
||
144 | final public function getDatabase() { |
||
147 | |||
148 | /** |
||
149 | * Prepare a binding. |
||
150 | * |
||
151 | * @param array $fields The fields. |
||
152 | * @return array Returns the binding as key => :key. |
||
153 | */ |
||
154 | final public function prepareBinding(array $fields) { |
||
161 | |||
162 | /** |
||
163 | * Prepare an INSERT SQL query. |
||
164 | * |
||
165 | * @param string $table The table. |
||
166 | * @param array $values The values [field => value]. |
||
167 | * @return string Returns the INSERT SQL query. |
||
168 | */ |
||
169 | final public function prepareInsert($table, array $values) { |
||
185 | |||
186 | /** |
||
187 | * Prepare an UPDATE SQL query. |
||
188 | * |
||
189 | * @param string $table The table. |
||
190 | * @param array $values The values [field => value] |
||
191 | * @return string Returns the UPDATE SQL query. |
||
192 | */ |
||
193 | final public function prepareUpdate($table, array $values) { |
||
212 | |||
213 | /** |
||
214 | * Set the authenticator. |
||
215 | * |
||
216 | * @param Authenticator $authenticator The authenticator. |
||
217 | * @return AbstractDatabase Returns this abstract database. |
||
218 | */ |
||
219 | final public function setAuthenticator(Authenticator $authenticator) { |
||
223 | |||
224 | /** |
||
225 | * Set the database. |
||
226 | * |
||
227 | * @param string $database The database. |
||
228 | * @return AbstractDatabase Returns this abstract database. |
||
229 | */ |
||
230 | final public function setDatabase($database) { |
||
234 | |||
235 | } |
||
236 |