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