简体   繁体   English

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

[英]How to connect Codeigniter with MSSQL (SQL Server)?

My server use Windows Server with MSSQL 2012. While I am use OS X (El Capitan) with XAMPP (Apache) for Mac and develop website using Codeigniter 2.2.0. 我的服务器使用Windows Server和MSSQL 2012.虽然我使用OS X(El Capitan)和XAMPP(Apache)for Mac并使用Codeigniter 2.2.0开发网站。

Here is my configuration : 这是我的配置:

$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;

but the results is : 但结果是:

1
Are my settings be wrong? 我的设置是错的吗?

I just want to be able to connect to that server. 我只是想能够连接到该服务器。 Does anyone have any advice on solving this? 有没有人有任何解决这个问题的建议?

You may want to try odbc driver (built-in db driver in PHP). 您可能想尝试odbc驱动程序(PHP中的内置数据库驱动程序)。 Mssql driver doesn't come convenient in PHP. PHP中的Mssql驱动程序不方便。

I got this working with CI 2.2.0 connected to MSSQL 2014 database (all Windows platform). 我使用CI 2.2.0连接到MSSQL 2014数据库(所有Windows平台)。 I've also tried this using MSSQL 2012 before. 我之前也尝试过使用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;

Note: 注意:

SQL Server Native Client 11.0 or SQL Server Native Client 10.0 , just play with both settings. SQL Server Native Client 11.0SQL Server Native Client 10.0 ,只需使用这两个设置。

Server=xx.xx.xx.x usually is in the format Server=Host\\Instance Server=xx.xx.xx.x通常采用Server=Host\\Instance格式 在此输入图像描述

it will be helpful for someone 这会对某人有所帮助

Detail steps for How to connect SQL Server with PHP in WampServer 有关如何在WampServer中将SQL Server与PHP连接的详细步骤

step 1) 第1步)

download the appropriate driver based on your php version, check using php_info() function, for me 5.6, so the appropriate driver is SQLSRV30, found in the following link https://www.microsoft.com/en-us/download/details.aspx?id=20098 根据你的php版本下载相应的驱动程序,检查使用php_info()函数,对我5.6,所以相应的驱动程序是SQLSRV30,可在以下链接中找到https://www.microsoft.com/en-us/download/details的.aspx?ID = 20098

step 2) extract the drives in C:\\wamp\\bin\\php\\php5.6.19\\ext focus on the following .dll file they should be there, otherwise we can't connect with SQL, these are 步骤2)在C:\\ wamp \\ bin \\ php \\ php5.6.19 \\ ext中提取驱动器,重点放在它们应该存在的以下.dll文件中,否则我们无法连接SQL,这些都是

php_sqlsrv_56_nts.dll and php_sqlsrv_56_ts.dll php_sqlsrv_56_nts.dll和php_sqlsrv_56_ts.dll

step 3) enable the drives in php.ini as follow, which is found in C:\\wamp\\bin\\apache\\apache2.4.18\\bin as follow 步骤3)启用php.ini中的驱动器,如下所示,可在C:\\ wamp \\ bin \\ apache \\ apache2.4.18 \\ bin中找到,如下所示

extension=php_sqlsrv_56_ts.dll extension=php_sqlsrv_56_nts.dll extension = php_sqlsrv_56_ts.dll extension = php_sqlsrv_56_nts.dll

step 4) go to DB_driver.php line 96 found in C:\\wamp\\www\\public\\system\\database\\DB_driver.php please replace the mysqli by sqlsrv 步骤4)转到C:\\ wamp \\ www \\ public \\ system \\ database \\ DB_driver.php中找到的DB_driver.php第96行请用sqlsrv替换mysqli

public $dbdriver = ' mysqli  '; 
 public $dbdriver = 'sqlsrv'; 

step 5) last and most important part, go to CI database config in database.php file which's found in C:\\wamp\\www\\public\\application\\config\\database.php adjust the params accordingly... 步骤5)最后也是最重要的部分,转到在C:\\ wamp \\ www \\ public \\ application \\ config \\ database.php中找到的database.php文件中的CI数据库配置相应地调整params ...

$db['default'] = array( $ 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

); );

happy coding... 快乐的编码......

The error is showing that SQLSRV driver implies the DLL is not loading ever. 该错误显示SQLSRV驱动程序暗示DLL未加载。 check your php_info() The SQLSRV driver requires for it. 检查你的php_info()SQLSRV驱动程序需要它。 check this for step by step solution 检查这是一步一步的解决方案

https://futbolsalas15.wordpress.com/2014/02/23/7-steps-to-make-sql-server-and-codeigniter-works/ https://futbolsalas15.wordpress.com/2014/02/23/7-steps-to-make-sql-server-and-codeigniter-works/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM