Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter无法连接到MSSQL数据库_Php_Sql Server_Codeigniter_Centos_Cpanel - Fatal编程技术网

Php Codeigniter无法连接到MSSQL数据库

Php Codeigniter无法连接到MSSQL数据库,php,sql-server,codeigniter,centos,cpanel,Php,Sql Server,Codeigniter,Centos,Cpanel,在CodeIgniter中我尝试连接到mssql(远程连接)时出错,无法连接到数据库,错误不会在每次连接时出现。有时似乎有时不是 这就是我无法获取数据的原因,如果连接问题反复出现,我的服务器会变慢 我的连接配置在这里 $db['mssql'] = array( 'dsn' => '', 'hostname' => 'IP,port', 'username' => '********', 'password' => '********',

在CodeIgniter中我尝试连接到mssql(远程连接)时出错,
无法连接到数据库
,错误不会在每次连接时出现。有时似乎有时不是

这就是我无法获取数据的原因,如果连接问题反复出现,我的服务器会变慢

我的连接配置在这里

$db['mssql'] = array(
    'dsn'   => '',
    'hostname' => 'IP,port',
    'username' => '********',
    'password' => '********',
    'database' => '********',
    'dbdriver' => 'sqlsrv',
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => (ENVIRONMENT !== 'production'),
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);
以及来自模型的示例查询

public function getBanks($accountCode,$currency){
    $this->Mssql = $this->load->database('mssql',TRUE);
    $this->Mssql->select('AccountingCode,BankName,BranchCode,BranchName,IbanNo');
    $this->Mssql->from('Bank');
    $this->Mssql->where(array('AccountingCode'=>$accountCode,'Curr'=>$currency));
    return $this->Mssql->get()->result();
}
服务器功能:
CodeIgniter 3.1
在centos VPS服务器上使用whm/cpanel

远程Mssql:Microsoft SQL Server 2008 R2(SP3)

编辑:有时查询需要很长时间或超时。但通常需要3-4秒。下面的长期示例

Uptime:  223 seconds
Executable: 
/opt/cpanel/ea-php73/root/usr/sbin/php-fpm
Command Line (often faked in exploits):
php-fpm: pool mydomian_com                         
Network connections by the process (if any):
tcp: centos:35097 -> mssql:1490
Files open by the process (if any):
/dev/null
/var/cpanel/php/sessions/ea- 
php73/ci_session2c2f2a2567083e33da437a984c0c6171352aa8eb

如果数据库和web脚本位于同一服务器中,则可以将localhost保留为主机名

$db['default'] = array(
'dsn'   => '',
'hostname' => "localhost",
'username' => "username",
'password' => "password",
'database' => "db_name",
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE

))

如果数据库和web脚本位于同一服务器中,则可以将localhost保留为主机名

$db['default'] = array(
'dsn'   => '',
'hostname' => "localhost",
'username' => "username",
'password' => "password",
'database' => "db_name",
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE

))

供参考;SQL Server 2008(R2)现在完全不受支持,强烈建议您尽快升级。如果它有时可以工作,但在您体验到服务器运行缓慢时失败,则听起来像是服务器问题,而不是PHP问题。@Lamu,我对此没有权限,@Magnus Eriksson,我认为缓慢的原因是在连接过程中无法得到答案,仅供参考;SQL Server 2008(R2)现在完全不受支持,强烈建议您尽快升级。如果它有时可以工作,但在您体验到服务器运行缓慢时失败,则听起来像是服务器问题,而不是PHP问题。@Lamu,我对此没有权限,@Magnus Eriksson,我认为速度慢的原因是它在连接期间无法得到答案MSQL数据库是远程的不在同一服务器中,db驱动程序应该是sqlsrv,因为数据库是sql server如果是远程服务器,请将IP保留为主机名,并在数据库服务器中将数据库服务器IP设置为绑定地址。。希望它能工作MSSQL数据库是远程的,不在同一台服务器上,db驱动程序应该是sqlsrv,因为数据库是sql server如果是远程服务器,请将IP作为主机名,并在数据库服务器中设置数据库服务器IP作为绑定地址。。希望它能起作用