Subversion Repositories PHPX

Rev

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

Rev 58 Rev 68
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 port on the host
-
 
15
   * @var int
-
 
16
   */
-
 
17
  protected $_port;
-
 
18
-
 
19
  /**
-
 
20
   * MySQL Unix socket (shouldn't be used with host or port).
-
 
21
   * @var string
-
 
22
   */
-
 
23
  protected $_unix_socket;
-
 
24
-
 
25
  /**
14
  * Database name
26
  * Database name
15
  * @var string
27
  * @var string
16
  */
28
  */
17
  protected $_dbname;
29
  protected $_dbname;
18
30
19
  /**
31
  /**
20
   * Username to access the database
32
   * Username to access the database
21
   * @var string
33
   * @var string
22
   */
34
   */
23
  protected $_username;
35
  protected $_username;
24
36
25
  /**
37
  /**
26
   * Password to access the database
38
   * Password to access the database
27
   * @var string
39
   * @var string
28
   */
40
   */
29
  protected $_password;
41
  protected $_password;
30
42
31
  /**
43
  /**
32
   * Optional charset parameter value
44
   * Optional charset parameter value
33
   * @var string
45
   * @var string
34
   */
46
   */
35
  protected $_charset = null;
47
  protected $_charset = null;
36
48
37
  /**
49
  /**
38
   * (non-PHPdoc)
50
   * (non-PHPdoc)
39
   * @see Database::_leftQuote
51
   * @see Database::_leftQuote
40
   */
52
   */
41
    protected $_leftQuote = '`';
53
    protected $_leftQuote = '`';
42
54
43
  /**
55
  /**
44
   * (non-PHPdoc)
56
   * (non-PHPdoc)
45
   * @see Database::_rightQuote
57
   * @see Database::_rightQuote
46
   */
58
   */
47
  protected $_rightQuote = '`';
59
  protected $_rightQuote = '`';
48
60
49
  public function __construct()
61
  public function __construct()
50
  {
62
  {
51
        $this->readConfig();
63
        $dbconfig = $this->readConfig();
-
 
64
        if ($dbconfig === false)
-
 
65
        {
-
 
66
          return;
-
 
67
        }
-
 
68
-
 
69
        if (isset($dbconfig['unix_socket']))
-
 
70
        {
-
 
71
          $this->_unix_socket = $dbconfig['unix_socket'];
-
 
72
        }
52
73
53
    $this->_dsn = "mysql:host={$this->_host}"
74
    $this->_dsn = "mysql:host={$this->_host}"
-
 
75
      . (!is_null($this->_port) ? ";port={$this->_port}" : '')
-
 
76
      . (!is_null($this->_unix_socket) ? ";unix_socket={$this->_unix_socket}" : '')
54
      . (!is_null($this->_dbname) ? ";dbname={$this->_dbname}" : '')
77
      . (!is_null($this->_dbname) ? ";dbname={$this->_dbname}" : '')
55
      . (!is_null($this->_charset) ? ";charset={$this->_charset}" : '');
78
      . (!is_null($this->_charset) ? ";charset={$this->_charset}" : '');
56
79
57
    if (!is_null($this->_charset))
80
    if (!is_null($this->_charset))
58
    {
81
    {
59
      $this->_options[\PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES " . $this->_charset;
82
      $this->_options[\PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES " . $this->_charset;
60
    }
83
    }
61
84
62
    parent::__construct();
85
    parent::__construct();
63
  }
86
  }
64
87
65
  /**
88
  /**
66
   * (non-PHPdoc)
89
   * (non-PHPdoc)
67
   * @see \PointedEars\PHPX\Db\Database::_columnDef()
90
   * @see \PointedEars\PHPX\Db\Database::_columnDef()
68
   */
91
   */
69
  protected function _columnDef (array $data, $columnName)
92
  protected function _columnDef (array $data, $columnName)
70
  {
93
  {
71
        $standard_Def = parent::_columnDef($data, $columnName);
94
        $standard_Def = parent::_columnDef($data, $columnName);
72
        $mySQL_def = $standardDef
95
        $mySQL_def = $standardDef
73
        . (isset($data['format'])  && $data['format']  ? " COLUMN_FORMAT {$data['format']}" : '')
96
        . (isset($data['format'])  && $data['format']  ? " COLUMN_FORMAT {$data['format']}" : '')
74
                  . (isset($data['storage']) && $data['storage'] ? " STORAGE {$data['storage']}"      : '');
97
                  . (isset($data['storage']) && $data['storage'] ? " STORAGE {$data['storage']}"      : '');
75
98
76
        return $mySQL_def;
99
        return $mySQL_def;
77
  }
100
  }
78
101
79
  /**
102
  /**
80
   * Creates this MySQL database
103
   * Creates this MySQL database
81
   *
104
   *
82
   * @param string $dsn
105
   * @param string $dsn
83
   *   Ignored.  Required for strict compatibility only.
106
   *   Ignored.  Required for strict compatibility only.
84
   * @param string $username = null
107
   * @param string $username = null
85
   * @param string $password = null
108
   * @param string $password = null
86
   * @param array? $options = null
109
   * @param array? $options = null
87
   *   Ignored.  Required for strict compatibility only.
110
   *   Ignored.  Required for strict compatibility only.
88
   * @param string $dbspec = null
111
   * @param string $dbspec = null
89
   *   Currently ignored.
112
   *   Currently ignored.
90
   * @param boolean $force = false
113
   * @param boolean $force = false
91
   * @see Database::create()
114
   * @see Database::create()
92
   */
115
   */
93
  public function create ($dsn, $username = null, $password = null,
116
  public function create ($dsn, $username = null, $password = null,
94
    array $options = null, $dbspec = null, $force = false)
117
    array $options = null, $dbspec = null, $force = false)
95
  {
118
  {
96
    return parent::create(
119
    return parent::create(
97
      "mysql:host={$this->_host}"
120
      "mysql:host={$this->_host}"
98
      . (!is_null($this->_charset) ? ";charset={$this->_charset}" : ''),
121
      . (!is_null($this->_charset) ? ";charset={$this->_charset}" : ''),
99
      $username, $password, null, $force);
122
      $username, $password, null, $force);
100
  }
123
  }
101
}
124
}