Skip to content
This repository was archived by the owner on Aug 13, 2023. It is now read-only.

Commit 693e38d

Browse files
committed
add cache system
1 parent c00d98a commit 693e38d

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

src/Database/Database.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Deimos\Config\ConfigObject;
66
use Deimos\Helper\Exceptions\ExceptionEmpty;
7+
use Deimos\QueryBuilder\AbstractAdapter;
78
use Deimos\QueryBuilder\Adapter;
89
use Deimos\QueryBuilder\Instruction;
910
use Deimos\QueryBuilder\QueryBuilder;
@@ -31,7 +32,7 @@ class Database
3132
];
3233

3334
/**
34-
* @var Adapter
35+
* @var AbstractAdapter
3536
*/
3637
protected $adapter;
3738

@@ -45,6 +46,11 @@ class Database
4546
*/
4647
protected $connection;
4748

49+
/**
50+
* @var \PDOStatement[]
51+
*/
52+
protected $statements = [];
53+
4854
/**
4955
* Database constructor.
5056
*
@@ -101,10 +107,14 @@ public function raw($sql, array $attributes = [])
101107
*/
102108
public function rawQuery($sql, array $attributes = [])
103109
{
104-
$statement = $this->connection()->prepare($sql);
105-
$statement->execute($attributes);
110+
if (empty($this->statements[$sql]))
111+
{
112+
$this->statements[$sql] = $this->connection()->prepare($sql);
113+
}
114+
115+
$this->statements[$sql]->execute($attributes);
106116

107-
return $statement;
117+
return $this->statements[$sql];
108118
}
109119

110120
/**
@@ -200,7 +210,6 @@ protected function connect()
200210
//Connection::ATTR_EMULATE_PREPARES => true,
201211
//Connection::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
202212
//Connection::ATTR_PERSISTENT => false,
203-
//Connection::ATTR_ERRMODE => Connection::ERRMODE_EXCEPTION,
204213
//Connection::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4'
205214
];
206215

0 commit comments

Comments
 (0)