Total Complexity | 6 |
Total Lines | 24 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
3 | class StmtCache { |
||
4 | private $pdo; |
||
5 | private $queryCache = []; |
||
6 | |||
7 | public function __construct(\PDO $pdo) { |
||
8 | $this->pdo = $pdo; |
||
9 | } |
||
10 | |||
11 | public function getCachedStmt($sql) { |
||
12 | $queryId = $this->getQueryId($sql); |
||
13 | if (isset($this->queryCache[$queryId])) $stmt = $this->queryCache[$queryId]; |
||
14 | else { |
||
15 | $stmt = $this->pdo->prepare($sql, [\PDO::ATTR_CURSOR => \PDO::CURSOR_FWDONLY]); |
||
16 | if ($stmt) $this->queryCache[$queryId] = $stmt; |
||
17 | } |
||
18 | return $stmt; |
||
19 | } |
||
20 | |||
21 | private function getQueryId($sql) { |
||
22 | return md5($sql); |
||
23 | } |
||
24 | |||
25 | public function deleteQueryFromCache($sql) { |
||
27 | } |
||
28 | } |
||
29 |