BUG 7798 Fix Bug in the connection to an instance for SQLServer database.

This commit is contained in:
Hector Cortez
2011-11-08 16:23:23 -04:00
parent 9b3921665f
commit cab6281d06
4 changed files with 48 additions and 18 deletions

View File

@@ -74,13 +74,14 @@ class MSSQLConnection extends ConnectionCommon implements Connection {
} else { } else {
$portDelimiter = ":"; $portDelimiter = ":";
} }
if(!empty($dsninfo['port'])) { if(!empty($dsninfo['port'])) {
$dbhost .= $portDelimiter.$dsninfo['port']; $dbhost .= $portDelimiter.$dsninfo['port'];
} else { } else {
$dbhost .= $portDelimiter.'1433'; if(!strpos($dbhost, "\\")){
} $dbhost .= $portDelimiter.'1433';
}
}
$connect_function = $persistent ? 'mssql_pconnect' : 'mssql_connect'; $connect_function = $persistent ? 'mssql_pconnect' : 'mssql_connect';
if ($dbhost && $user && $pw) { if ($dbhost && $user && $pw) {

View File

@@ -16,6 +16,7 @@ class NET
private $db_passwd; private $db_passwd;
private $db_sourcename; private $db_sourcename;
private $db_port; private $db_port;
private $db_instance;
/*errors handle*/ /*errors handle*/
public $error; public $error;
@@ -31,6 +32,7 @@ class NET
{ {
$this->errno = 0; $this->errno = 0;
$this->errstr = ""; $this->errstr = "";
$this->db_instance = "";
unset($this->db_user); unset($this->db_user);
unset($this->db_passwd); unset($this->db_passwd);
@@ -52,16 +54,23 @@ class NET
*/ */
function resolv($pHost) function resolv($pHost)
{ {
if ($this->is_ipaddress($pHost)) { $aHost = explode("\\", $pHost);
$this->ip = $pHost; if(count($aHost)>1){
if (!$this->hostname = @gethostbyaddr($pHost)) { $ipHost = $aHost[0];
$this->db_instance = $aHost[1];
} else {
$ipHost = $pHost;
}
if ($this->is_ipaddress($ipHost)) {
$this->ip = $ipHost;
if (!$this->hostname = @gethostbyaddr($ipHost)) {
$this->errno = 2000; $this->errno = 2000;
$this->errstr = "NET::Host down"; $this->errstr = "NET::Host down";
$this->error = "Destination Host Unreachable"; $this->error = "Destination Host Unreachable";
} }
} }
else { else {
$ip = @gethostbyname($pHost); $ip = @gethostbyname($ipHost);
$long = ip2long($ip); $long = ip2long($ip);
if ( $long == -1 || $long === FALSE) { if ( $long == -1 || $long === FALSE) {
$this->errno = 2000; $this->errno = 2000;
@@ -69,7 +78,7 @@ class NET
$this->error = "Destination Host Unreachable"; $this->error = "Destination Host Unreachable";
} }
else { else {
$this->ip = @gethostbyname($pHost); $this->ip = @gethostbyname($ipHost);
$this->hostname = $pHost; $this->hostname = $pHost;
} }
} }
@@ -219,9 +228,14 @@ class NET
break; break;
case 'mssql': case 'mssql':
$str_port = (($this->db_port == "") || ($this->db_port == 0) || ($this->db_port == 1433)) ? "" : ":".$this->db_port; if($this->db_instance != ""){
$link = @mssql_connect($this->ip . $str_port, $this->db_user, $this->db_passwd); $str_port = "";
$link = @mssql_connect($this->ip . "\\". $this->db_instance, $this->db_user, $this->db_passwd);
} else {
$str_port = (($this->db_port == "") || ($this->db_port == 0) || ($this->db_port == 1433)) ? "" : ":".$this->db_port;
$link = @mssql_connect($this->ip . $str_port, $this->db_user, $this->db_passwd);
}
if ($link) { if ($link) {
$stat->status = 'SUCCESS'; $stat->status = 'SUCCESS';
$this->errstr = ""; $this->errstr = "";
@@ -339,8 +353,15 @@ class NET
break; break;
case 'mssql': case 'mssql':
$str_port = (($this->db_port == "") || ($this->db_port == 0) || ($this->db_port == 1433)) ? "" : ":".$this->db_port; // $str_port = (($this->db_port == "") || ($this->db_port == 0) || ($this->db_port == 1433)) ? "" : ":".$this->db_port;
$link = @mssql_connect($this->ip . $str_port, $this->db_user, $this->db_passwd); // $link = @mssql_connect($this->ip . $str_port, $this->db_user, $this->db_passwd);
if($this->db_instance != ""){
$str_port = "";
$link = @mssql_connect($this->ip . "\\". $this->db_instance, $this->db_user, $this->db_passwd);
} else {
$str_port = (($this->db_port == "") || ($this->db_port == 0) || ($this->db_port == 1433)) ? "" : ":".$this->db_port;
$link = @mssql_connect($this->ip . $str_port, $this->db_user, $this->db_passwd);
}
if ($link) { if ($link) {
$db = @mssql_select_db($this->db_sourcename, $link); $db = @mssql_select_db($this->db_sourcename, $link);
if ($db) { if ($db) {

View File

@@ -147,6 +147,8 @@ switch ( $action ){
$oDBSource = new DbSource(); $oDBSource = new DbSource();
$oContent = new Content(); $oContent = new Content();
if(strpos($_POST['server'], "\\"))
$_POST['port'] = 'none';
$aData = Array( $aData = Array(
'DBS_UID' => $_POST['dbs_uid'], 'DBS_UID' => $_POST['dbs_uid'],
'PRO_UID' => $_SESSION['PROCESS'], 'PRO_UID' => $_SESSION['PROCESS'],
@@ -168,6 +170,8 @@ switch ( $action ){
$oDBSource = new DbSource(); $oDBSource = new DbSource();
$oContent = new Content(); $oContent = new Content();
if(strpos($_POST['server'], "\\"))
$_POST['port'] = 'none';
$aData = Array( $aData = Array(
'PRO_UID' => $_SESSION['PROCESS'], 'PRO_UID' => $_SESSION['PROCESS'],
'DBS_TYPE' => $_POST['type'], 'DBS_TYPE' => $_POST['type'],

View File

@@ -13,7 +13,11 @@ if( isset($_SESSION['PROCESS']) ){
$db['DBS_PASSWORD'] = $oDbConnections->getPassWithoutEncrypt($db); $db['DBS_PASSWORD'] = $oDbConnections->getPassWithoutEncrypt($db);
$dbsPort = ($db['DBS_PORT'] == '') ? ('') : (':'.$db['DBS_PORT']); $dbsPort = ($db['DBS_PORT'] == '') ? ('') : (':'.$db['DBS_PORT']);
$ENCODE = (trim($db['DBS_ENCODE']) == '')? '': '?encoding=' . $db['DBS_ENCODE']; $ENCODE = (trim($db['DBS_ENCODE']) == '')? '': '?encoding=' . $db['DBS_ENCODE'];
$pro['datasources'][$db['DBS_UID']]['connection'] = $db['DBS_TYPE'] . '://' . $db['DBS_USERNAME'] . ':' . $db['DBS_PASSWORD'] . '@' . $db['DBS_SERVER'] .$dbsPort. '/' . $db['DBS_DATABASE_NAME'] . $ENCODE; if(strpos($db['DBS_SERVER'], "\\") && $db['DBS_TYPE'] == 'mssql'){
$pro['datasources'][$db['DBS_UID']]['connection'] = $db['DBS_TYPE'] . '://' . $db['DBS_USERNAME'] . ':' . $db['DBS_PASSWORD'] . '@' . $db['DBS_SERVER'] . '/' . $db['DBS_DATABASE_NAME'] . $ENCODE;
} else {
$pro['datasources'][$db['DBS_UID']]['connection'] = $db['DBS_TYPE'] . '://' . $db['DBS_USERNAME'] . ':' . $db['DBS_PASSWORD'] . '@' . $db['DBS_SERVER'] .$dbsPort. '/' . $db['DBS_DATABASE_NAME'] . $ENCODE;
}
$pro['datasources'][$db['DBS_UID']]['adapter'] = $db['DBS_TYPE']; $pro['datasources'][$db['DBS_UID']]['adapter'] = $db['DBS_TYPE'];
} }
return $pro; return $pro;