![](/img/trans.png)
[英]Unexpected error, the message was : Unable to connect to the database server 'localhost' EZ Publish
[英]Error: Message: Unable to connect to the database
我在用
1- Windows Server 2012 R2
2- SQL Server 2014
3- Codeigniter 3.1
4- PHP 5.6
5-php_sqlsrv_56_ts.dll
我有時會收到此錯誤:
An uncaught Exception was encountered
Type: RuntimeException
Message: Unable to connect to the database.
Filename: C:\wed\wed\system\database\DB_driver.php Line Number: 433
Backtrace:
File: C:\wed\wed\web\application\core\MY_Controller.php Line: 10
Function: __construct
File: C:\wed\wed\web\application\controllers\sanjeh.php Line: 12
Function: __construct
File: C:\wed\wed\web\index.php Line: 317
Function: require_once
轉到應用程序/配置/數據庫
https://codeigniter.com/user_guide/database/configuration.html
並設置
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'database_name',
'dbdriver' => 'mysqli',
對於SQLSRV驅動程序顯示的錯誤表明DLL從未加載。 您的php_info()說什么?
另外,您是否安裝了SQL Server本機訪問客戶端(SNAC)10? SQLSRV驅動程序需要它。
CodeIgniter的內置ODBC驅動程序,該驅動程序在表名周圍添加撇號。 我快速瀏覽了odbc_driver.php,更改了引用表的方式,從而解決了該問題
//Database Config file database.php in My case
$db['default']['hostname'] = "Driver={SQLServer};Server=127.0.0.1\YouSqlServerName;Database=DBName;Uid=username;Pwd=password;";
$db['default']['port'] = '1433';
$db['default']['username'] = 'username';
$db['default']['password'] = 'password';
$db['default']['database'] = 'DBName';
$db['default']['dbdriver'] = 'odbc';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.