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