Subversion Repositories PHPX

Rev

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