1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace Nette\Database\Drivers;
13:
14: use Nette;
15:
16:
17:
18: 19: 20: 21: 22:
23: class PdoMySqlDriver extends Nette\Object implements Nette\Database\ISupplementalDriver
24: {
25:
26: private $connection;
27:
28:
29:
30: 31: 32: 33: 34:
35: public function __construct(Nette\Database\Connection $connection, array $options)
36: {
37: $this->connection = $connection;
38: $charset = isset($options['charset']) ? $options['charset'] : 'utf8';
39: if ($charset) {
40: $connection->exec("SET NAMES '$charset'");
41: }
42: if (isset($options['sqlmode'])) {
43: $connection->exec("SET sql_mode='$options[sqlmode]'");
44: }
45: $connection->exec("SET time_zone='" . date('P') . "'");
46: }
47:
48:
49:
50:
51:
52:
53:
54: 55: 56:
57: public function delimite($name)
58: {
59: 60: return '`' . str_replace('`', '``', $name) . '`';
61: }
62:
63:
64:
65: 66: 67:
68: public function formatDateTime(\DateTime $value)
69: {
70: return $value->format("'Y-m-d H:i:s'");
71: }
72:
73:
74:
75: 76: 77:
78: public function formatLike($value, $pos)
79: {
80: $value = addcslashes(str_replace('\\', '\\\\', $value), "\x00\n\r\\'%_");
81: return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'");
82: }
83:
84:
85:
86: 87: 88:
89: public function applyLimit(&$sql, $limit, $offset)
90: {
91: if ($limit < 0 && $offset < 1) return;
92:
93: 94: $sql .= ' LIMIT ' . ($limit < 0 ? '18446744073709551615' : (int) $limit)
95: . ($offset > 0 ? ' OFFSET ' . (int) $offset : '');
96: }
97:
98:
99:
100: 101: 102:
103: public function normalizeRow($row, $statement)
104: {
105: return $row;
106: }
107:
108: }
109: