Codeigniter未连接到SQL Server [英] Codeigniter Not Connecting to SQL Server
问题描述
我正在尝试使用CodeIgniter连接到SQL Server。如果使用sqlsrv驱动程序-会收到致命错误消息,如果使用odbc驱动程序-会出现‘无法使用提供的设置错误消息连接到数据库服务器。有谁知道如何解决这个问题???我不介意,我只是想让Codeigniter连接到SQL Server数据库。
I'm trying to connect to an SQL server using CodeIgniter. If I use the sqlsrv driver - I get a fatal error message and if I use the odbc driver - I get an 'Unable to connect to your database server using the provided settings error message. Does anyone know how to fix this problem??? I don't mind how, I just want Codeigniter to connect to the SQL Server Database.
这是数据库配置文件
$db['otherdb']['hostname'] = '195.234.10.55\SQLEXPRESS';
$db['otherdb']['username'] = 'username';
$db['otherdb']['password'] = 'password';
$db['otherdb']['database'] = 'ONEDB';
$db['otherdb']['dbdriver'] = 'odbc'; // Done this in both ODBC and SQLSRV
$db['otherdb']['dbprefix'] = '';
$db['otherdb']['pconnect'] = TRUE;
$db['otherdb']['db_debug'] = TRUE;
$db['otherdb']['cache_on'] = FALSE;
$db['otherdb']['cachedir'] = '';
$db['otherdb']['char_set'] = 'utf8';
$db['otherdb']['dbcollat'] = 'utf8_general_ci';
$db['otherdb']['swap_pre'] = '';
$db['otherdb']['autoinit'] = TRUE;
$db['otherdb']['stricton'] = FALSE;
谢谢
推荐答案
(不是要复活一个旧帖子,但以防万一其他人正在寻找答案,因为这个帖子是在我搜索期间出现的...)
使用本地驱动程序从CodeIgniter 3连接到SQL_server的简短分步指南:
A short step-by-step guide to connect to SQL_server from CodeIgniter 3 using native driver:
- 首先从 http下载SQL Server SQL Server Microsoft本机驱动程序://www.microsoft.com/zh-cn/download/details.aspx?id = 20098 。请注意选择适合您的设置的一种。
-
将其安装到PHP扩展目录。
- First of all download PHP for SQL_server Microsoft native driver from http://www.microsoft.com/en-us/download/details.aspx?id=20098. Take care to choose the one that fits your setup.
Install it to the PHP extension directory.
在PHP.ini中配置新扩展名。取消注释或附加行(取决于所选的驱动程序版本)。即:
Configure the new extension in PHP.ini. uncommenting or appending the line (depending on the choosen driver version). I.e.:
extension = php_sqlsrv_55_ts.dll
重新启动Apache。
Restart Apache.
现在,您的PHP设置能够连接到SQL_server数据库。
Now your PHP setup is able to connect to SQL_server databases.
通过配置application / config / database.php来设置CodeIgniter数据库连接,例如
Set up your CodeIgniter database connection by configuring application/config/database.php like
<?php
// native-driver connection
$db['default'] = array(
'dsn' => '',
'hostname' => 'SERVER\SQLEXPRESS',
'username' => 'test_user',
'password' => 'test_password',
'database' => 'test01',
'dbdriver' => 'sqlsrv',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => 'application/cache',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'autoinit' => TRUE,
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
在SQL_server 2008 R2和SQL_server 2014 Express上从CodeIgniter 3.0.1测试。
这篇关于Codeigniter未连接到SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!