Rev 27 | Rev 32 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
27 | PointedEar | 1 | <?php |
2 | |||
29 | PointedEar | 3 | require_once __DIR__ . '/Database.php'; |
27 | PointedEar | 4 | |
5 | class MySQLDB extends Database |
||
6 | { |
||
7 | /** |
||
8 | * Database host |
||
9 | * @var string |
||
10 | */ |
||
11 | protected $_host; |
||
12 | |||
13 | /** |
||
14 | * Database name |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $_dbname; |
||
18 | |||
19 | /** |
||
20 | * Username to access the database |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $_username; |
||
24 | |||
25 | /** |
||
26 | * Password to access the database |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $_password; |
||
30 | |||
31 | /* |
||
32 | * Optional charset parameter value |
||
33 | */ |
||
34 | protected $_charset = null; |
||
35 | |||
36 | public function __construct() |
||
37 | { |
||
38 | $this->_dsn = "mysql:host={$this->_host}" |
||
39 | . (!is_null($this->_dbname) ? ";dbname={$this->_dbname}" : '') |
||
40 | . (!is_null($this->_charset) ? ";charset={$this->_charset}" : ''); |
||
41 | |||
42 | if (!is_null($this->_charset)) |
||
43 | { |
||
44 | $this->_options[PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES " . $this->_charset; |
||
45 | } |
||
46 | |||
47 | parent::__construct(); |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * Escapes a database name so that it can be used in a query. |
||
52 | * |
||
53 | * @param string $name |
||
54 | * The name to be escaped |
||
55 | * @return string |
||
56 | * The escaped name |
||
57 | */ |
||
58 | public function escapeName($name) |
||
59 | { |
||
60 | return '`' . $name . '`'; |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * (non-PHPdoc) |
||
65 | * @see Database::_escapeAliasArray() |
||
66 | */ |
||
67 | protected function _escapeAliasArray(array &$array) |
||
68 | { |
||
69 | foreach ($array as $column => &$value) |
||
70 | { |
||
71 | $value = $value . ' AS `' . $column . '`'; |
||
72 | } |
||
73 | |||
74 | return $array; |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * (non-PHPdoc) |
||
79 | * @see Database::_escapeValueArray() |
||
80 | */ |
||
81 | protected function _escapeValueArray(array &$array, $suffix = '', array &$escape = array('`', '`')) |
||
82 | { |
||
83 | return parent::_escapeValueArray($array, $suffix, $escape); |
||
84 | } |
||
85 | } |