1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* |
5
|
|
|
* This file is part of the Apix Project. |
6
|
|
|
* |
7
|
|
|
* (c) Franck Cassedanne <franck at ouarz.net> |
8
|
|
|
* |
9
|
|
|
* @license http://opensource.org/licenses/BSD-3-Clause New BSD License |
10
|
|
|
* |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Apix\Cache\Pdo; |
14
|
|
|
|
15
|
|
|
use Apix\Cache\AbstractPdo; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* The Mysql (PDO) wrapper. |
19
|
|
|
* |
20
|
|
|
* @author Franck Cassedanne <franck at ouarz.net> |
21
|
|
|
*/ |
22
|
|
View Code Duplication |
class Mysql extends AbstractPdo |
23
|
|
|
{ |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Holds the SQL definitions for MySQL 3.x, 4.x and 5.x. |
27
|
|
|
*/ |
28
|
|
|
protected $sql_definitions = array( |
29
|
|
|
'init' => 'CREATE TABLE IF NOT EXISTS %s (`key` VARCHAR(255) NOT NULL, |
30
|
|
|
`data` LONGTEXT NULL, `tags` TEXT NULL, `expire` INTEGER |
31
|
|
|
UNSIGNED, `dated` TIMESTAMP, PRIMARY KEY (`key`)) |
32
|
|
|
ENGINE=MYISAM DEFAULT charset=utf8;', |
33
|
|
|
'key_idx' => 'CREATE INDEX `%s_key_idx` ON `%s` (`key`);', |
34
|
|
|
'exp_idx' => 'CREATE INDEX `%s_exp_idx` ON `%s` (`expire`);', |
35
|
|
|
|
36
|
|
|
// 'tag_idx' will throw MYSQL ERROR 1170 -- if the index is needed then |
37
|
|
|
// we should split keys and tags into diff tables and use varchar(255). |
38
|
|
|
// 'tag_idx' => 'CREATE INDEX `%s_tag_idx` ON `%s` (`tags`);', |
|
|
|
|
39
|
|
|
|
40
|
|
|
'loadKey' => 'SELECT `data`, `expire` FROM `%s` WHERE `key`=:key AND |
41
|
|
|
(`expire` IS NULL OR `expire` > :now);', |
42
|
|
|
'loadTag' => 'SELECT `key` FROM `%s` WHERE `tags` LIKE :tag AND |
43
|
|
|
(`expire` IS NULL OR `expire` > :now);', |
44
|
|
|
'update' => 'UPDATE `%s` SET `data`=:data, `tags`=:tags, `expire`=:exp, |
45
|
|
|
`dated`=:dated WHERE `key`=:key;', |
46
|
|
|
'insert' => 'INSERT INTO `%s` (`key`, `data`, `tags`, `expire`, `dated`) |
47
|
|
|
VALUES (:key, :data, :tags, :exp, :dated);', |
48
|
|
|
'delete' => 'DELETE FROM `%s` WHERE `key`=?;', |
49
|
|
|
'clean' => 'DELETE FROM `%s` WHERE %s;', // %s 'clean_like' iterated |
50
|
|
|
'clean_like'=> 'tags LIKE ?', |
51
|
|
|
'flush_all' => 'DROP TABLE IF EXISTS `%s`;', |
52
|
|
|
'flush' => 'DELETE FROM `%s`;', |
53
|
|
|
'purge' => 'DELETE FROM `%s` WHERE `expire` IS NOT NULL AND `expire` < %d;' |
54
|
|
|
); |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Constructor. |
58
|
|
|
* |
59
|
|
|
* @param \PDO $pdo |
60
|
|
|
* @param array $options Array of options. |
61
|
|
|
*/ |
62
|
46 |
|
public function __construct(\PDO $pdo, array $options=null) |
63
|
|
|
{ |
64
|
46 |
|
parent::__construct($pdo, $options); |
65
|
46 |
|
} |
66
|
|
|
|
67
|
|
|
} |
68
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.