Subversion Repositories PHPX

Rev

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