在 Xampp 中连接 sqlsrv [英] Connect sqlsrv in Xampp

查看:21
本文介绍了在 Xampp 中连接 sqlsrv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过 CodeIgniter 安装安装了 Xampp.我想从 CodeIgniter 连接到 SQL 数据库.

I have installed Xampp with a CodeIgniter installation. I want to connect from CodeIgniter to a SQL database.

我更改了数据库配置文件并将 dbdriver 设置为 sqlsrv.

I changed the database config file and set the dbdriver to sqlsrv.

$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'IP Adress;
$db['default']['username'] = 'DBUserName';
$db['default']['password'] = 'DBPassword';
$db['default']['database'] = 'DBName';
$db['default']['dbdriver'] = 'sqlsrv';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

在我的控制器中,我有以下代码来尝试连接:

In my controller I have the following code to try the connection:

$this->load->database();

$db_obj = $this->db->load('sql_Test',TRUE);
$connected = $db_obj->initialize();

if (!$connected){
    $db_obj = $this->d->load('yyy',TRUE);
} 
else{
    die('connected');
}

我有以下错误:

致命错误:调用未定义的函数 sqlsrv_connect() inC:xampphtdocssystemdatabasedriverssqlsrvsqlsrv_driver.php 上第 76 行

Fatal error: Call to undefined function sqlsrv_connect() in C:xampphtdocssystemdatabasedriverssqlsrvsqlsrv_driver.php on line 76

我在一个论坛上读到我必须从 sqlsrv_driver.php 更改第 89 行:

I have read on a forum that I have to change line 89 from sqlsrv_driver.php:

function db_pconnect()
{
    // $this->db_connect(TRUE); original
    return $this->db_connect(TRUE);
}

我做错了什么?

推荐答案

EDIT-首先你需要下载驱动http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx

EDIT- First you need to download the driver http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx

现在转到您的 XAMPP 安装并搜索 php.dll它将显示您拥有的正确 PHP dll.

Now go to your XAMPP installation and search for php.dll It will display correct PHP dll you have.

1) 将以下文件移动到 xampp/php/ext 目录.

1) move following files to xampp/php/ext directory.

php_sqlsrv_53_nts_vc9.dll
php_pdo_sqlsrv_53_nts_vc9.dll

2) 如果您有 php5ts.dll,则将以下文件移动到 xampp/php/ext 目录.

2) If you have php5ts.dll then move following files to xampp/php/ext directory.

php_sqlsrv_53_ts_vc9.dll
php_pdo_sqlsrv_53_ts_vc9.dll

如果您的 PHP 版本是使用 Visual C++ 9.0 编译的,则应使用上述文件.否则应使用以下文件.

above files should be used if your PHP version is compiled with Visual C++ 9.0 . Else following files should be used.

1) 如果您有 php.dll,则将以下文件移动到 xampp/php/ext 目录.

1) If you have php.dll then move following files to xampp/php/ext directory.

php_sqlsrv_53_nts_vc6.dll
php_pdo_sqlsrv_53_nts_vc6.dll

2) 如果您有 php5ts.dll,则将以下文件移动到 xampp/php/ext 目录.

2) If you have php5ts.dll then move following files to xampp/php/ext directory.

php_sqlsrv_53_ts_vc6.dll
php_pdo_sqlsrv_53_ts_vc6.dll

现在我们必须加载我们最近添加的文件.打开php ini文件,在动态扩展区添加如下条目.

Now we have to load files that we added recently. Open the php ini file and add entry in the area of dynamic extensions as follow.

extension=php_sqlsrv_53_nts_vc9.dll
extension= php_pdo_sqlsrv_53_nts_vc9 .dll 

保存ini文件并重启XAMPP

Save the ini files and restart XAMPP

$check= @$CI->load->database($config, TRUE); // ommit the error
if ($check->call_function('error') !== 0) {
    // Failed to connect
}

<小时>

我不确定您要做什么,但在 codeigniter 中您不需要初始化数据库,CI 会自动为您完成


I don't know for sure what you are trying to do but in codeigniter you don't need to initialise database, CI automatically does it for you

所以-

$this->load->database();

$db_obj = $this->db->load('SQL_Test',TRUE);
$connected = $db_obj->initialize();

这不是必需的.

您只需要加载模型并在模型中开始执行查询.$this->load->database();在控制器中,您需要加载模型,例如-

You just need to load the model and in model start performing queries. $this->load->database(); In controller you need to load the model like-

$this->load->model('my_model');

然后调用您在其中编写查询的模型函数.

then call the model function in which you have written the queries.

$this->my_model->myfunction(); 

这篇关于在 Xampp 中连接 sqlsrv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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