Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php MSSQL服务器未在codeigniter中配置。i、 e.不建立联系_Php_Sql Server_Database_Codeigniter_Sqlsrv - Fatal编程技术网

Php MSSQL服务器未在codeigniter中配置。i、 e.不建立联系

Php MSSQL服务器未在codeigniter中配置。i、 e.不建立联系,php,sql-server,database,codeigniter,sqlsrv,Php,Sql Server,Database,Codeigniter,Sqlsrv,我在codeigniter中与数据库建立连接时遇到问题。我已经尝试了很多,也测试了很多不同的人给出的解决方案,但到目前为止都没有成功 我在codeigniter中的配置是: $db['default']['hostname'] = 'DX-PC\MSSQLSERVER'; //$db['default']['port'] = 1433; $db['default']['username'] = 'myusername'; $db['default']['password'] = 'mypass'

我在codeigniter中与数据库建立连接时遇到问题。我已经尝试了很多,也测试了很多不同的人给出的解决方案,但到目前为止都没有成功

我在codeigniter中的配置是:

$db['default']['hostname'] = 'DX-PC\MSSQLSERVER';
//$db['default']['port'] = 1433;
$db['default']['username'] = 'myusername';
$db['default']['password'] = 'mypass';
$db['default']['database'] = 'mydbname';
$db['default']['dbdriver'] = 'sqlsrv';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE; //default: 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;
因此,它给出了以下错误:

发生数据库错误 无法使用提供的设置连接到数据库服务器

同样,我也尝试了在不使用codeigniter的情况下通过以下代码与MS SQL server建立连接:

    echo 'called';

    echo "<br>";

    $serverName = "DX-PC\\MSSQLSERVER"; //serverName\instanceName
    $connectionInfo = array( "Database"=>"mydbname", "UID"=>"myusername", "PWD"=>"mypass");
    $conn = sqlsrv_connect( $serverName,$connectionInfo);
    if( $conn ) {
        echo "Connection established.<br />";
    }else{
        echo "Connection could not be established.<br />";
        echo "<pre>";
        print_r(sqlsrv_errors());
        echo "</pre>";
    }
)


我尝试了来自不同论坛和stackoverflow的所有解决方案,但都没有成功。请帮帮我。谢谢

过去我也有问题,所以我用经典的方式来做:


是的,我已经弄明白了,它现在正在工作。 以下更改使其正常工作

  • 以前的配置,就像您以前必须完成的一样。i、 e.(扩展名:sqlsrv_*.dll等添加到php.ini等中)

  • 将.htaccess中的重写规则从RewriteRule^(.)$/index.php?/$1[L]更改为RewriteRule^(.)$/yourrootfolder/index.php?/$1[L](由SHAZ提供)

  • 其次,因为我有一个名为MSSQLSERVER的默认实例,所以它不需要写入$db['default']['hostname']='DX-PC\MSSQLSERVER';而是写$db['default']['hostname']='DX-PC'


  • 我希望这能帮助别人。谢谢。

    在.htaccess文件中,检查或更正您的url:
    RewriteRule^(.*)$/yourRootFolder/index.php?/$1[L]
    RewriteEngine On RewriteBase/cheddargeter/RewriteCond%{REQUEST\u FILENAME}-f RewriteCond%{REQUEST_FILENAME}-重写规则^(.*)$/cheddargeter/index.php?/$1[L]我已更改它。仍在获取数据库错误
    called Connection could not be established.
    
    Array
      (
        [0] => Array
           (
            [0] => 08001
            [SQLSTATE] => 08001
            [1] => 87
            [code] => 87
            [2] => [Microsoft][ODBC Driver 11 for SQL Server]SQL Server Network Interfaces: Connection string is not valid [87]. 
            [message] => [Microsoft][ODBC Driver 11 for SQL Server]SQL Server Network Interfaces: Connection string is not valid [87]. 
        )
    
    [1] => Array
        (
            [0] => HYT00
            [SQLSTATE] => HYT00
            [1] => 0
            [code] => 0
            [2] => [Microsoft][ODBC Driver 11 for SQL Server]Login timeout expired
            [message] => [Microsoft][ODBC Driver 11 for SQL Server]Login timeout expired
        )
    
    [2] => Array
        (
            [0] => 08001
            [SQLSTATE] => 08001
            [1] => 87
            [code] => 87
            [2] => [Microsoft][ODBC Driver 11 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.
            [message] => [Microsoft][ODBC Driver 11 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.
        )
    
    $server = "x.x.x.x\MSSQL2005,1435";
    $user = "xxxx";
    $pass = "xxxx";
    
    $this->ms  = mssql_connect($server, $user, $pass) or die ("No connection");