我的服务器使用Windows Server和MSSQL 2012.虽然我使用OS X(El Capitan)和XAMPP(Apache)for Mac并使用Codeigniter 2.2.0开发网站。
这是我的配置:
$active_group = 'my_mssql';
$active_record = TRUE;
$db['my_mssql']['hostname'] = 'xx.xx.xx.x';
$db['my_mssql']['username'] = 'wow_queue';
$db['my_mssql']['password'] = 'wow12345';
$db['my_mssql']['database'] = 'queue_sys';
$db['my_mssql']['dbdriver'] = 'mssql';
$db['my_mssql']['dbprefix'] = '';
$db['my_mssql']['pconnect'] = TRUE;
$db['my_mssql']['db_debug'] = TRUE;
$db['my_mssql']['cache_on'] = FALSE;
$db['my_mssql']['cachedir'] = '';
$db['my_mssql']['char_set'] = 'utf8';
$db['my_mssql']['dbcollat'] = 'utf8_general_ci';
$db['my_mssql']['swap_pre'] = '';
$db['my_mssql']['autoinit'] = TRUE;
$db['my_mssql']['stricton'] = FALSE;
但结果是:
我的设置是错的吗?
我只是想能够连接到该服务器。有没有人有任何解决这个问题的建议?
您可能想尝试odbc驱动程序(PHP中的内置数据库驱动程序)。 PHP中的Mssql驱动程序不方便。
我使用CI 2.2.0连接到MSSQL 2014数据库(所有Windows平台)。我之前也尝试过使用MSSQL 2012。
$active_group = 'my_mssql';
$active_record = TRUE;
$db['my_mssql']['hostname'] = 'Driver={SQL Server Native Client 11.0};Server=Host\Instance;Database=queue_sys;';
$db['my_mssql']['username'] = 'wow_queue';
$db['my_mssql']['password'] = 'wow12345';
$db['my_mssql']['database'] = '';
$db['my_mssql']['dbdriver'] = 'odbc';
$db['my_mssql']['dbprefix'] = '';
$db['my_mssql']['pconnect'] = FALSE;
$db['my_mssql']['db_debug'] = TRUE;
$db['my_mssql']['cache_on'] = FALSE;
$db['my_mssql']['cachedir'] = '';
$db['my_mssql']['char_set'] = 'utf8';
$db['my_mssql']['dbcollat'] = 'utf8_general_ci';
$db['my_mssql']['swap_pre'] = '';
$db['my_mssql']['autoinit'] = TRUE;
$db['my_mssql']['stricton'] = FALSE;
注意:
SQL Server Native Client 11.0
或SQL Server Native Client 10.0
,只是玩两种设置。
这会对某人有所帮助
有关如何在WampServer中将SQL Server与PHP连接的详细步骤
步骤1)
根据你的php版本下载相应的驱动程序,使用php_info()函数检查,对我来说5.6,所以相应的驱动程序是SQLSRV30,可在以下链接找到https://www.microsoft.com/en-us/download/details.aspx?id=20098
步骤2)在C:\ wamp \ bin \ php \ php5.6.19 \ ext中提取驱动器,重点放在它们应该存在的以下.dll文件中,否则我们无法连接SQL,这些都是
php_sqlsrv_56_nts.dll和php_sqlsrv_56_ts.dll
步骤3)启用php.ini中的驱动器,如下所示,可在C:\ wamp \ bin \ apache \ apache2.4.18 \ bin中找到,如下所示
extension = php_sqlsrv_56_ts.dll extension = php_sqlsrv_56_nts.dll
步骤4)转到C:\ wamp \ www \ public \ system \ database \ DB_driver.php中找到的DB_driver.php第96行请用sqlsrv替换mysqli
public $dbdriver = ' mysqli ';
public $dbdriver = 'sqlsrv';
步骤5)最后也是最重要的部分,转到在C:\ wamp \ www \ public \ application \ config \ database.php中找到的database.php文件中的CI数据库配置相应地调整params ...
$ db ['default'] = array(
'dsn' => '',
'hostname' => 'ip address for sql server,port', // it should be SQL TCP enabled and firewall permitted for SQL port, whether default or custom.
'username' => 'your user name here',
'password' => 'your pwd here',
'database' => 'your db here',
'dbdriver' => 'sqlsrv',
'dbprefix' => '',
'pconnect' => TRUE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'autoinit' => TRUE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
快乐的编码......
该错误显示SQLSRV驱动程序暗示DLL未加载。检查你的php_info()SQLSRV驱动程序需要它。检查这是一步一步的解决方案
https://futbolsalas15.wordpress.com/2014/02/23/7-steps-to-make-sql-server-and-codeigniter-works/