如何将Codeigniter与MSSQL(SQL Server)连接? [英] How to connect Codeigniter with MSSQL (SQL Server)?

查看:118
本文介绍了如何将Codeigniter与MSSQL(SQL Server)连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的服务器使用Windows Server和MSSQL2012.同时我将OS X(El Capitan)和XAMPP(Apache)用于Mac,并使用Codeigniter 2.2.0开发网站.

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.

这是我的配置:

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

但结果是:


我的设置有误吗?


Are my settings be wrong?

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

I just want to be able to connect to that server. Does anyone have any advice on solving this?

推荐答案

这将对某人有所帮助

有关如何在WampServer中将SQL Server与PHP连接的详细步骤

Detail steps for How to connect SQL Server with PHP in WampServer

第1步)

根据您的php版本下载适当的驱动程序,对我来说使用php_info()函数进行检查5.6,因此适当的驱动程序为SQLSRV30,可在以下链接中找到 https://www.microsoft.com/zh-cn/download/details.aspx?id = 20098

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

步骤2)将驱动器解压缩到C:\ wamp \ bin \ php \ php5.6.19 \ ext 重点关注以下应存在的.dll文件,否则我们将无法与SQL连接,这些是

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

php_sqlsrv_56_nts.dll和php_sqlsrv_56_ts.dll

php_sqlsrv_56_nts.dll and php_sqlsrv_56_ts.dll

第3步)启用php.ini中的驱动器 如下,在C:\ wamp \ bin \ apache \ apache2.4.18 \ bin中可以找到

step 3) enable the drives in php.ini as follow, which is found in C:\wamp\bin\apache\apache2.4.18\bin as follow

extension = php_sqlsrv_56_ts.dll 扩展程序= php_sqlsrv_56_nts.dll

extension=php_sqlsrv_56_ts.dll extension=php_sqlsrv_56_nts.dll

第4步)转到DB_driver.php第96行 在发现 C:\ wamp \ www \ public \ system \ database \ DB_driver.php 请用sqlsrv替换mysqli

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

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

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

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...

$ 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

);

快乐的编码...

这篇关于如何将Codeigniter与MSSQL(SQL Server)连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆