简体   繁体   English

Codeigniter中如何连接mssql?

[英]How to connect mssql in Codeigniter?

I am trying to connect codeigniter with MSSQL.我正在尝试将 codeigniter 与 MSSQL 连接起来。 I have done all possible changes in the php.ini file by adding the extensions extension=php_sqlsrv_56_ts.dll and extension=php_pdo_sqlsrv_56_ts.dll .我通过添加扩展extension=php_sqlsrv_56_ts.dllextension=php_pdo_sqlsrv_56_ts.dllphp.ini文件进行了所有可能的更改。 But still am facing sqlsrv error as follow,但仍然面临如下 sqlsrv 错误,

Error: Message: sqlsrv_query() expects parameter 1 to be resource, null given错误:消息:sqlsrv_query() 期望参数 1 是资源,给定 null

sqlsrv_driver.php sqlsrv_driver.php

function _execute($sql)
{
    $sql = $this->_prep_query($sql);
    return sqlsrv_query($this->conn_id, $sql, null, array(
        'Scrollable'                => SQLSRV_CURSOR_STATIC,
        'SendStreamParamsAtExec'    => true
    ));
}

$this->conn_id --- this is empty. $this->conn_id --- 这是空的。 I don't know why its getting null value.我不知道为什么它得到 null 值。

Codeigniter Version: 2.2 / Codeigniter 版本:2.2 /
PHP Version: 5.6 PHP 版本:5.6

Database configuration:数据库配置:

$db['default']['hostname'] = '.\sqlexpress';
$db['default']['username'] = 'UNAME';
$db['default']['password'] = '';
$db['default']['database'] = 'DBNAME'; 
$db['default']['dbdriver'] = 'sqlsrv';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = FALSE;
$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;

NOTE: I have been stuck in this for past 3 day and i have tried.注意:过去 3 天我一直被困在这个问题上,我已经尝试过了。 Since i am new to MSSQL, i cant able to figure out the problem.由于我是 MSSQL 的新手,我无法找出问题所在。 Any help in this would be much appreciated.对此的任何帮助将不胜感激。 Thanks in advance.提前致谢。

在此处输入图像描述

You are running an unsupported version of PHP.您正在运行不受支持的 PHP 版本。 You need to upgrade your PHP version to continue to receive security updates.您需要升级 PHP 版本才能继续接收安全更新。 See https://php.net/supported-versions.php .请参阅https://php.net/supported-versions.php

Doing this would also give you access to newer versions of the sqlsrv drivers.这样做还可以让您访问更新版本的 sqlsrv 驱动程序。 This is important because your current driver cannot connect to newer versions of SQL Server.这很重要,因为您当前的驱动程序无法连接到较新版本的 SQL 服务器。

You've stated you're using SQL 2017. However as per the Microsoft PHP Drivers for SQL Server Support Matrix , with PHP version 5.6 you can only run version 3.2 of the sqlsrv drivers, and version 3.2 of the drivers only supports SQL 2014 and below. You've stated you're using SQL 2017. However as per the Microsoft PHP Drivers for SQL Server Support Matrix , with PHP version 5.6 you can only run version 3.2 of the sqlsrv drivers, and version 3.2 of the drivers only supports SQL 2014 and以下。

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

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