Subversion Repositories PHPX

Rev

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

Rev 52 Rev 58
1
<?php
1
<?php
2
2
3
namespace PointedEars\PHPX\Db;
3
namespace PointedEars\PHPX\Db;
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
   * @var string
33
   * @var string
34
   */
34
   */
35
  protected $_charset = null;
35
  protected $_charset = null;
36
36
37
  /**
37
  /**
38
   * (non-PHPdoc)
38
   * (non-PHPdoc)
39
   * @see Database::_leftQuote
39
   * @see Database::_leftQuote
40
   */
40
   */
41
    protected $_leftQuote = '`';
41
    protected $_leftQuote = '`';
42
42
43
  /**
43
  /**
44
   * (non-PHPdoc)
44
   * (non-PHPdoc)
45
   * @see Database::_rightQuote
45
   * @see Database::_rightQuote
46
   */
46
   */
47
  protected $_rightQuote = '`';
47
  protected $_rightQuote = '`';
48
48
49
  public function __construct()
49
  public function __construct()
50
  {
50
  {
51
        $this->readConfig();
51
        $this->readConfig();
52
52
53
    $this->_dsn = "mysql:host={$this->_host}"
53
    $this->_dsn = "mysql:host={$this->_host}"
54
      . (!is_null($this->_dbname) ? ";dbname={$this->_dbname}" : '')
54
      . (!is_null($this->_dbname) ? ";dbname={$this->_dbname}" : '')
55
      . (!is_null($this->_charset) ? ";charset={$this->_charset}" : '');
55
      . (!is_null($this->_charset) ? ";charset={$this->_charset}" : '');
56
56
57
    if (!is_null($this->_charset))
57
    if (!is_null($this->_charset))
58
    {
58
    {
59
      $this->_options[\PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES " . $this->_charset;
59
      $this->_options[\PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES " . $this->_charset;
60
    }
60
    }
61
61
62
    parent::__construct();
62
    parent::__construct();
63
  }
63
  }
64
64
65
  /**
65
  /**
-
 
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
  /**
66
   * Creates this MySQL database
80
   * Creates this MySQL database
67
   *
81
   *
68
   * @param string $dsn
82
   * @param string $dsn
69
   *   Ignored.  Required for strict compatibility only.
83
   *   Ignored.  Required for strict compatibility only.
70
   * @param string $username = null
84
   * @param string $username = null
71
   * @param string $password = null
85
   * @param string $password = null
72
   * @param array? $options = null
86
   * @param array? $options = null
73
   *   Ignored.  Required for strict compatibility only.
87
   *   Ignored.  Required for strict compatibility only.
74
   * @param string $dbspec = null
88
   * @param string $dbspec = null
75
   *   Currently ignored.
89
   *   Currently ignored.
76
   * @param boolean $force = false
90
   * @param boolean $force = false
77
   * @see Database::create()
91
   * @see Database::create()
78
   */
92
   */
79
  public function create ($dsn, $username = null, $password = null,
93
  public function create ($dsn, $username = null, $password = null,
80
    array $options = null, $dbspec = null, $force = false)
94
    array $options = null, $dbspec = null, $force = false)
81
  {
95
  {
82
    return parent::create(
96
    return parent::create(
83
      "mysql:host={$this->_host}"
97
      "mysql:host={$this->_host}"
84
      . (!is_null($this->_charset) ? ";charset={$this->_charset}" : ''),
98
      . (!is_null($this->_charset) ? ";charset={$this->_charset}" : ''),
85
      $username, $password, null, $force);
99
      $username, $password, null, $force);
86
  }
100
  }
87
}
101
}