Subversion Repositories PHPX

Rev

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

Rev 29 Rev 32
1
<?php
1
<?php
2
2
3
require_once __DIR__ . '/Database.php';
3
require_once __DIR__ . '/Database.php';
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
   */
33
   */
34
  protected $_charset = null;
34
  protected $_charset = null;
35
 
35
 
-
 
36
  /**
-
 
37
   * (non-PHPdoc)
-
 
38
   * @see Database::_leftQuote
-
 
39
   */
-
 
40
    protected $_leftQuote = '`';
-
 
41
 
-
 
42
  /**
-
 
43
   * (non-PHPdoc)
-
 
44
   * @see Database::_rightQuote
-
 
45
   */
-
 
46
  protected $_rightQuote = '`';
-
 
47
 
36
  public function __construct()
48
  public function __construct()
37
  {
49
  {
38
    $this->_dsn = "mysql:host={$this->_host}"
50
    $this->_dsn = "mysql:host={$this->_host}"
39
      . (!is_null($this->_dbname) ? ";dbname={$this->_dbname}" : '')
51
      . (!is_null($this->_dbname) ? ";dbname={$this->_dbname}" : '')
40
      . (!is_null($this->_charset) ? ";charset={$this->_charset}" : '');
52
      . (!is_null($this->_charset) ? ";charset={$this->_charset}" : '');
41
   
53
   
42
    if (!is_null($this->_charset))
54
    if (!is_null($this->_charset))
43
    {
55
    {
44
      $this->_options[PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES " . $this->_charset;
56
      $this->_options[PDO::MYSQL_ATTR_INIT_COMMAND] = "SET NAMES " . $this->_charset;
45
    }
57
    }
46
   
58
   
47
    parent::__construct();
59
    parent::__construct();
48
  }
60
  }
49
 
-
 
50
  /**
-
 
51
   * Escapes a database name so that it can be used in a query.
-
 
52
   *
-
 
53
   * @param string $name
-
 
54
   *   The name to be escaped
-
 
55
   * @return string
-
 
56
   *   The escaped name
-
 
57
   */
-
 
58
  public function escapeName($name)
-
 
59
  {
-
 
60
    return '`' . $name . '`';
-
 
61
  }
-
 
62
-
 
63
  /**
-
 
64
   * (non-PHPdoc)
-
 
65
   * @see Database::_escapeAliasArray()
-
 
66
   */
-
 
67
  protected function _escapeAliasArray(array &$array)
-
 
68
  {
-
 
69
    foreach ($array as $column => &$value)
-
 
70
    {
-
 
71
      $value = $value . ' AS `' . $column . '`';
-
 
72
    }
-
 
73
 
-
 
74
    return $array;
-
 
75
  }
-
 
76
-
 
77
  /**
-
 
78
   * (non-PHPdoc)
-
 
79
   * @see Database::_escapeValueArray()
-
 
80
   */
-
 
81
  protected function _escapeValueArray(array &$array, $suffix = '', array &$escape = array('`', '`'))
-
 
82
  {
-
 
83
    return parent::_escapeValueArray($array, $suffix, $escape);
-
 
84
  }
-
 
85
}
61
}
86
62