Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/84.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(SQL Server)连接?_Php_Sql_Sql Server_Codeigniter_Database Connection - Fatal编程技术网

Php 如何将Codeigniter与MSSQL(SQL Server)连接?

Php 如何将Codeigniter与MSSQL(SQL Server)连接?,php,sql,sql-server,codeigniter,database-connection,Php,Sql,Sql Server,Codeigniter,Database Connection,我的服务器与MSSQL 2012一起使用Windows server。当我在Mac上使用OSX(ElCapitan)和XAMPP(Apache),并使用CodeIgniter2.2.0开发网站时 以下是我的配置: $active_group = 'my_mssql'; $active_record = TRUE; $db['my_mssql']['hostname'] = 'xx.xx.xx.x'; $db['my_mssql']['username'] = 'wow_queue'; $db[

我的服务器与MSSQL 2012一起使用Windows server。当我在Mac上使用OSX(ElCapitan)和XAMPP(Apache),并使用CodeIgniter2.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;
但结果是:


我的设置有错吗


我只想能够连接到那个服务器。有人对解决这个问题有什么建议吗?

错误显示SQLSRV驱动程序暗示DLL从未加载过。 检查您的php_信息() SQLSRV驱动程序需要它。 检查此项以获得逐步解决方案


您可能需要尝试odbc驱动程序(PHP中的内置db驱动程序)。Mssql驱动程序在PHP中并不方便

我使用连接到MSSQL 2014数据库(所有Windows平台)的CI 2.2.0实现了这一点。我以前也曾使用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本机客户端11.0
SQL Server本机客户端10.0
,只需使用这两种设置即可

Server=xx.xx.xx.x
的格式通常为
Server=Host\Instance

这对某人会有帮助

详细介绍如何在WampServer中连接SQL Server和PHP的步骤

步骤1)

根据您的php版本下载适当的驱动程序,使用php_info()函数检查,对于me 5.6,因此适当的驱动程序是SQLSRV30,可在以下链接中找到

步骤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\u sqlsrv\u 56\u ts.dll extension=php\u sqlsrv\u 56\u nts.dll

步骤4)转到DB_driver.php第96行 发现于 C:\wamp\www\public\system\database\DB\u driver.php 请将mysqli替换为sqlsrv

public $dbdriver = ' mysqli  '; 
 public $dbdriver = 'sqlsrv'; 
步骤5)最后也是最重要的部分,转到CI数据库配置 在C:\wamp\www\public\application\config\database.php中找到的database.php文件中 相应地调整参数

$db['default']=数组(

))


快乐编码…

可能的答案如果我在Codeigniter中使用MSSQL驱动程序会怎么样?我使用OSX。。不是窗户。
'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