【发布时间】:2015-03-09 05:28:56
【问题描述】:
我在使用 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 服务器建立连接:
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>";
}
它给了我这些错误:
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.
)
)
我已经尝试了来自不同论坛和 stackoverflow 的所有解决方案,但没有成功。请帮助我。谢谢
【问题讨论】:
-
在 .htaccess 文件中,检查或更正您的网址:
RewriteRule ^(.*)$ /yourRootFolder/index.php?/$1 [L] -
RewriteEngine On RewriteBase /cheddargetter/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /cheddargetter/index.php? /$1 [L] 我已经改变了它。仍然出现 db 错误
标签: php sql-server database codeigniter sqlsrv