1 | <?php |
||
25 | class DB extends AbstractAnonymizer |
||
26 | { |
||
27 | /** |
||
28 | * The PDO connection |
||
29 | * |
||
30 | * @var \PDO |
||
31 | */ |
||
32 | private $pdo; |
||
33 | |||
34 | /** |
||
35 | * Prepared statement is stored for the update, to make the queries faster |
||
36 | * |
||
37 | * @var \PDOStatement |
||
38 | */ |
||
39 | private $preparedStmt; |
||
40 | |||
41 | /** |
||
42 | * Constructor |
||
43 | * |
||
44 | * @param \PDO $pdo |
||
45 | */ |
||
46 | 2 | public function __construct(\PDO $pdo) |
|
51 | |||
52 | /** |
||
53 | * Process an entity by reading / writing to the DB |
||
54 | * |
||
55 | * @param string $table |
||
56 | * @param callable|null $callback |
||
57 | * @param bool $pretend |
||
58 | * @param bool $returnResult |
||
59 | * |
||
60 | * @return void|array |
||
61 | */ |
||
62 | 1 | public function processEntity( |
|
109 | |||
110 | /** |
||
111 | * Identify the primary key for a table |
||
112 | * |
||
113 | * @param string $table |
||
114 | * |
||
115 | * @return string Field's name |
||
116 | */ |
||
117 | 1 | protected function getPrimaryKey(string $table) |
|
133 | |||
134 | /** |
||
135 | * Execute the Update with PDO |
||
136 | * |
||
137 | * @param string $table Name of the table |
||
138 | * @param array $data Array of fields => value to update the table |
||
139 | * @param string $primaryKey |
||
140 | * @param string $val Primary Key's Value |
||
141 | */ |
||
142 | 1 | private function runUpdate(string $table, array $data, string $primaryKey, $val) |
|
160 | |||
161 | /** |
||
162 | * Prepare the statement if asked |
||
163 | * |
||
164 | * @param string $table |
||
165 | * @param string $primaryKey |
||
166 | * @param array $fieldNames |
||
167 | * |
||
168 | * @return \PDOStatement |
||
169 | */ |
||
170 | 1 | private function prepareStmt(string $table, string $primaryKey, array $fieldNames) |
|
179 | |||
180 | /** |
||
181 | * Execute the Delete with PDO |
||
182 | * |
||
183 | * @param string $table |
||
184 | * @param string $where |
||
185 | * @param bool $pretend |
||
186 | * |
||
187 | * @return string |
||
188 | */ |
||
189 | private function runDelete(string $table, string $where, bool $pretend): string |
||
206 | |||
207 | /** |
||
208 | * Build the SQL just for debug |
||
209 | * |
||
210 | * @param string $table |
||
211 | * @param array $data |
||
212 | * @param string $where |
||
213 | * |
||
214 | * @return string |
||
215 | */ |
||
216 | private function buildUpdateSQL(string $table, array $data, string $where): string |
||
227 | } |
||
228 |