PHP 连接 MSSQL用port时候的注意事项

项目中用CI的数据库类连接mssql,默认的端口port连接方法是","连接:

$this->hostname .= ','.$this->port;

但是在我的电脑上不能用,会报错。改成":"即可正常使用。

 

      总觉得CI框架中不应该犯这么个错误。先是百度了一下,没有任何相关的解释。如是在php.net 上在mssql_connect下面,看到了如下的解释:

The MS SQL server. It can also include a port number, e.g. hostname:port (Linux), or hostname,port(Windows).

原因正是因为我的系统是linux环境,不能用微软的sqlsrv,所以用mssql_connect的时候,出现这个问题。

修改如下:

	function db_connect()
	{
		if ($this->port != '')
		{
			if(strtoupper(substr(PHP_OS,0,3)) === 'WIN')
			{
				$this->hostname .= ','.$this->port;
			}
			else
			{
				$this->hostname .= ':'.$this->port;
			}
		}

		return @mssql_connect($this->hostname, $this->username, $this->password);
	}

  

posted @ 2014-10-14 09:56  wykuger  阅读(325)  评论(0编辑  收藏  举报