* Db/Database.php - Added general support for the `port' parameter * Db/Database.php, Db/MySQLDB.php - Added support for the `port' and `unix_socket' parameters
/trunk/Db/Database.php |
---|
152,9 → 152,9 |
* were set. That is, definitions in the class file |
* override those in the configuration file. |
* |
* @return array|boolean |
* The configuration array if the configuration |
* file could be read, <code>false</code> otherwise. |
* @return boolean|array |
* <code>true</code> if the configuration |
* file could be read, the configuration array otherwise. |
*/ |
public function readConfig () |
{ |
165,11 → 165,7 |
if (isset($config[$section])) |
{ |
$dbconfig = $config[$section]; |
$options = array( |
'host', 'port', 'dbname', 'username', 'password', 'charset' |
); |
foreach ($options as $key) |
foreach (array('host', 'dbname', 'username', 'password', 'charset') as $key) |
{ |
$property = "_$key"; |
if (isset($dbconfig[$key]) |
180,8 → 176,6 |
$this->$property = $dbconfig[$key]; |
} |
} |
return $config[$section]; |
} |
} |
/trunk/Db/MySQLDB.php |
---|
11,18 → 11,6 |
protected $_host; |
/** |
* Database port on the host |
* @var int |
*/ |
protected $_port; |
/** |
* MySQL Unix socket (shouldn't be used with host or port). |
* @var string |
*/ |
protected $_unix_socket; |
/** |
* Database name |
* @var string |
*/ |
60,20 → 48,9 |
public function __construct() |
{ |
$dbconfig = $this->readConfig(); |
if ($dbconfig === false) |
{ |
return; |
} |
$this->readConfig(); |
if (isset($dbconfig['unix_socket'])) |
{ |
$this->_unix_socket = $dbconfig['unix_socket']; |
} |
$this->_dsn = "mysql:host={$this->_host}" |
. (!is_null($this->_port) ? ";port={$this->_port}" : '') |
. (!is_null($this->_unix_socket) ? ";unix_socket={$this->_unix_socket}" : '') |
. (!is_null($this->_dbname) ? ";dbname={$this->_dbname}" : '') |
. (!is_null($this->_charset) ? ";charset={$this->_charset}" : ''); |