1 | <?php |
||
11 | class MySql implements EnkiInterface |
||
12 | { |
||
13 | use LoggedClassTrait; |
||
14 | |||
15 | /** |
||
16 | * @var \PDO |
||
17 | */ |
||
18 | private $pdo; |
||
19 | |||
20 | /** |
||
21 | * Provides a MySQL connection interface that catches a PDOException on failure. |
||
22 | * |
||
23 | * @param string $host The host name for the MySQL connection |
||
24 | * @param string $user The username for the MySQL connection |
||
25 | * @param string $pass The password for the MySQL connection |
||
26 | * @param string $name The database name for the MySQL connection |
||
27 | * |
||
28 | * @return bool Returns true if the connection was successful; returns false otherwise |
||
29 | */ |
||
30 | 13 | public function connect($host, $user, $pass, $name) |
|
51 | |||
52 | /** |
||
53 | * Destroys an existing PDO connection |
||
54 | * |
||
55 | * @return bool Returns true if the connection existed and was destroyed; returns false otherwise |
||
56 | */ |
||
57 | 2 | public function disconnect() |
|
69 | |||
70 | /** |
||
71 | * Gets the column names for all primary keys for a table or returns false if no keys exist |
||
72 | * |
||
73 | * @param string $table The table from which keys will be retrieved |
||
74 | * |
||
75 | * @return string|false Returns a string of column names representing primary keys; |
||
76 | * returns false if the table has no primary keys |
||
77 | */ |
||
78 | 8 | public function getPrimaryKeys($table) |
|
94 | |||
95 | /** |
||
96 | * Retrieves a row represented by a single primary key |
||
97 | * |
||
98 | * @param int|string $id A unique id for a table |
||
99 | * @param string $table The table from which a row will be retrieved |
||
100 | * |
||
101 | * @return array|false Returns an associative array representing the row corresponding with the primary key; |
||
102 | * returns false if the table does not exist, if the provided id does not correspond with a |
||
103 | * record, or if the table has a compound primary key |
||
104 | */ |
||
105 | 5 | public function getRowById($id, $table) |
|
125 | |||
126 | /** |
||
127 | * Determines whether a given table exists |
||
128 | * |
||
129 | * @param string $table The table that will be checked for existence |
||
130 | * @return bool Returns true if the table exists; returns false otherwise |
||
131 | */ |
||
132 | 2 | public function tableExists($table) |
|
148 | |||
149 | /** |
||
150 | * Processes the result set from a primary key query |
||
151 | * |
||
152 | * @see MySql::getPrimaryKeys() |
||
153 | * |
||
154 | * @param array $result An array representing the result of a primary key query |
||
155 | * |
||
156 | * @return string|false Returns a string column name if the result set contains only one primary key; |
||
157 | * returns false otherwise |
||
158 | */ |
||
159 | 5 | private function processPrimaryKeyResult($result) |
|
176 | |||
177 | /** |
||
178 | * Prepares a variable for a query string by surrounding it with single quotes if it's a string |
||
179 | * |
||
180 | * @param mixed $var The variable to be assessed for quoting |
||
181 | * |
||
182 | * @return mixed Returns the single-quoted variable if the variable is a string; returns the variable |
||
183 | * otherwise |
||
184 | */ |
||
185 | 5 | private function quoteQueryStringVariable($var) |
|
195 | |||
196 | /** |
||
197 | * A wrapper for executing PDOStatement objects that either returns the statement execution result or |
||
198 | * catches any PDOException thrown and updates the class logger with the exception message. |
||
199 | * |
||
200 | * @param \PDOStatement $statement The statement to be executed |
||
201 | * @param string|null $log_message OPTIONAL: The message to be logged, in addition to the PDOException message |
||
202 | * |
||
203 | * @return array|false Returns an associative array of the statement execution result of execution |
||
204 | * was successful; returns false otherwise |
||
205 | */ |
||
206 | 8 | private function statementWrapper(\PDOStatement $statement, $log_message = null) |
|
228 | } |
||
229 |