Rev 51 | Rev 58 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 51 | Rev 52 | ||
---|---|---|---|
1 | <?php
|
1 | <?php
|
2 | 2 | ||
3 | namespace PointedEars\PHPX\Db; |
3 | namespace PointedEars\PHPX\Db; |
4 | 4 | ||
5 | require_once __DIR__ . '/Database.php'; |
- | |
6 | - | ||
7 | class MySQLDB extends Database |
5 | class MySQLDB extends Database |
8 | {
|
6 | {
|
9 | /**
|
7 | /**
|
10 | * Database host
|
8 | * Database host
|
11 | * @var string
|
9 | * @var string
|
12 | */
|
10 | */
|
13 | protected $_host; |
11 | protected $_host; |
14 | 12 | ||
15 | /**
|
13 | /**
|
16 | * Database name
|
14 | * Database name
|
17 | * @var string
|
15 | * @var string
|
18 | */
|
16 | */
|
19 | protected $_dbname; |
17 | protected $_dbname; |
20 | 18 | ||
21 | /**
|
19 | /**
|
22 | * Username to access the database
|
20 | * Username to access the database
|
23 | * @var string
|
21 | * @var string
|
24 | */
|
22 | */
|
25 | protected $_username; |
23 | protected $_username; |
26 | 24 | ||
27 | /**
|
25 | /**
|
28 | * Password to access the database
|
26 | * Password to access the database
|
29 | * @var string
|
27 | * @var string
|
30 | */
|
28 | */
|
31 | protected $_password; |
29 | protected $_password; |
32 | 30 | ||
33 | /**
|
31 | /**
|
34 | * Optional charset parameter value
|
32 | * Optional charset parameter value
|
35 | * @var string
|
33 | * @var string
|
36 | */
|
34 | */
|
37 | protected $_charset = null; |
35 | protected $_charset = null; |
38 | 36 | ||
39 | /**
|
37 | /**
|
40 | * (non-PHPdoc)
|
38 | * (non-PHPdoc)
|
41 | * @see Database::_leftQuote
|
39 | * @see Database::_leftQuote
|
42 | */
|
40 | */
|
43 | protected $_leftQuote = '`'; |
41 | protected $_leftQuote = '`'; |
44 | 42 | ||
45 | /**
|
43 | /**
|
46 | * (non-PHPdoc)
|
44 | * (non-PHPdoc)
|
47 | * @see Database::_rightQuote
|
45 | * @see Database::_rightQuote
|
48 | */
|
46 | */
|
49 | protected $_rightQuote = '`'; |
47 | protected $_rightQuote = '`'; |
50 | 48 | ||
51 | public function __construct() |
49 | public function __construct() |
52 | {
|
50 | {
|
53 | $this->readConfig(); |
51 | $this->readConfig(); |
54 | 52 | ||
55 | $this->_dsn = "mysql:host={$this->_host}" |
53 | $this->_dsn = "mysql:host={$this->_host}" |
56 | . (!is_null($this->_dbname) ? ";dbname={$this->_dbname}" : '') |
54 | . (!is_null($this->_dbname) ? ";dbname={$this->_dbname}" : '') |
57 | . (!is_null($this->_charset) ? ";charset={$this->_charset}" : ''); |
55 | . (!is_null($this->_charset) ? ";charset={$this->_charset}" : ''); |
58 | 56 | ||
59 | if (!is_null($this->_charset)) |
57 | if (!is_null($this->_charset)) |
60 | {
|
58 | {
|
61 | $this->_options[\PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES " . $this->_charset; |
59 | $this->_options[\PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES " . $this->_charset; |
62 | }
|
60 | }
|
63 | 61 | ||
64 | parent::__construct(); |
62 | parent::__construct(); |
65 | }
|
63 | }
|
66 | 64 | ||
67 | /**
|
65 | /**
|
68 | * Creates this MySQL database
|
66 | * Creates this MySQL database
|
69 | *
|
67 | *
|
70 | * @param string $dsn
|
68 | * @param string $dsn
|
71 | * Ignored. Required for strict compatibility only.
|
69 | * Ignored. Required for strict compatibility only.
|
72 | * @param string $username = null
|
70 | * @param string $username = null
|
73 | * @param string $password = null
|
71 | * @param string $password = null
|
74 | * @param array? $options = null
|
72 | * @param array? $options = null
|
75 | * Ignored. Required for strict compatibility only.
|
73 | * Ignored. Required for strict compatibility only.
|
76 | * @param string $dbspec = null
|
74 | * @param string $dbspec = null
|
77 | * Currently ignored.
|
75 | * Currently ignored.
|
78 | * @param boolean $force = false
|
76 | * @param boolean $force = false
|
79 | * @see Database::create()
|
77 | * @see Database::create()
|
80 | */
|
78 | */
|
81 | public function create ($dsn, $username = null, $password = null, |
79 | public function create ($dsn, $username = null, $password = null, |
82 | array $options = null, $dbspec = null, $force = false) |
80 | array $options = null, $dbspec = null, $force = false) |
83 | {
|
81 | {
|
84 | return parent::create( |
82 | return parent::create( |
85 | "mysql:host={$this->_host}"
|
83 | "mysql:host={$this->_host}"
|
86 | . (!is_null($this->_charset) ? ";charset={$this->_charset}" : ''), |
84 | . (!is_null($this->_charset) ? ";charset={$this->_charset}" : ''), |
87 | $username, $password, null, $force); |
85 | $username, $password, null, $force); |
88 | }
|
86 | }
|
89 | }
|
87 | }
|