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

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

问题描述

我已经安装Xampp与CodeIgniter安装。我想从CodeIgniter连接到SQL数据库。



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

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

$ db ['default'] ['hostname'] ='IP地址;
$ 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;

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

  $ 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()C:\ xampp\htdocs\system\database\drivers\sqlsrv\sqlsrv_driver .php on
line 76


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

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

我错了什么?

解决方案

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



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



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

  php_sqlsrv_53_nts_vc9.dll 
php_pdo_sqlsrv_53_nts_vc9.dll
pre>

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

  php_sqlsrv_53_ts_vc9.dll 
php_pdo_sqlsrv_53_ts_vc9.dll

如果您的PHP版本使用Visual C ++ 9.0编译,应该使用文件。还应使用以下文件。



1)如果您有php.dll,请将以下文件移至xampp / php / ext目录。

  php_sqlsrv_53_nts_vc6.dll 
php_pdo_sqlsrv_53_nts_vc6.dll

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

  php_sqlsrv_53_ts_vc6 .dll 
php_pdo_sqlsrv_53_ts_vc6.dll

现在我们要加载我们最近添加的文件。打开php ini文件,并在动态扩展区域中添加条目,如下所示。

  extension = php_sqlsrv_53_nts_vc9.dll 
extension = php_pdo_sqlsrv_53_nts_vc9 .dll

保存ini文件并重新启动XAMPP






  $ check = @ $ CI-> load-> database($ config,TRUE); //忽略错误
if($ check-> call_function('error')!== 0){
//无法连接
}






我不知道你想要做什么,但在codeigniter无需初始化数据库,CI会自动为您处理。



so-

  $ this-> load-> database(); 

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

不需要。



只需要加载模型并在模型中开始执行查询。
$ this-> load-> database();
在控制器中你需要加载模型像 -

  $ this-> load-& my_model'); 

然后调用已写入查询的模型函数。

  $ this-> my_model-> myfunction(); 


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

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');
}

I have the following error:

Fatal error: Call to undefined function sqlsrv_connect() in C:\xampp\htdocs\system\database\drivers\sqlsrv\sqlsrv_driver.php on line 76

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);
}

What do I wrong?

解决方案

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

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

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

php_sqlsrv_53_nts_vc9.dll
php_pdo_sqlsrv_53_nts_vc9.dll

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

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

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

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 

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
}


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

so-

$this->load->database();

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

this is not needed.

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天全站免登陆