Subversion Repositories PHPX

Rev

Rev 47 | Rev 52 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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