check for database port behind hostname

This commit is contained in:
Uwe Steinmann 2014-01-28 08:10:47 +01:00
parent bb11cebc2e
commit b07869a3bb

View File

@ -37,6 +37,11 @@ class SeedDMS_Core_DatabaseAccess {
*/ */
protected $_hostname; protected $_hostname;
/**
* @var int port number of database
*/
protected $_port;
/** /**
* @var string name of database * @var string name of database
*/ */
@ -125,7 +130,11 @@ class SeedDMS_Core_DatabaseAccess {
*/ */
function SeedDMS_Core_DatabaseAccess($driver, $hostname, $user, $passw, $database = false) { /* {{{ */ function SeedDMS_Core_DatabaseAccess($driver, $hostname, $user, $passw, $database = false) { /* {{{ */
$this->_driver = $driver; $this->_driver = $driver;
$this->_hostname = $hostname; $tmp = explode(":", $hostname);
$this->_hostname = $tmp[0];
$this->_port = null;
if(!empty($tmp[1]))
$this->_port = $tmp[1];
$this->_database = $database; $this->_database = $database;
$this->_user = $user; $this->_user = $user;
$this->_passw = $passw; $this->_passw = $passw;
@ -156,6 +165,8 @@ class SeedDMS_Core_DatabaseAccess {
case 'mysqli': case 'mysqli':
case 'mysqlnd': case 'mysqlnd':
$dsn = $this->_driver.":dbname=".$this->_database.";host=".$this->_hostname; $dsn = $this->_driver.":dbname=".$this->_database.";host=".$this->_hostname;
if($this->_port)
$dsn .= ";port=".$this->_port;
break; break;
case 'sqlite': case 'sqlite':
$dsn = $this->_driver.":".$this->_database; $dsn = $this->_driver.":".$this->_database;