0

I am using

1- Windows Server 2012 R2

2- SQL Server 2014

3- Codeigniter 3.1

4- PHP 5.6

5- php_sqlsrv_56_ts.dll

I get this error sometimes:

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
Michele La Ferla
  • 6,775
  • 11
  • 53
  • 79
M.Ghavam
  • 101
  • 4
  • 16

2 Answers2

0

Go application/config/database

https://codeigniter.com/user_guide/database/configuration.html

and set

    'hostname' => 'localhost',
    'username' => 'root',
    'password' => '',
    'database' => 'database_name',
    'dbdriver' => 'mysqli',
Przemek eS
  • 1,224
  • 1
  • 8
  • 21
  • What? I dont use MySQL – M.Ghavam Jan 17 '17 at 12:24
  • @M.Ghavam try this in 'dbdriver' => 'sqlsrv' or 'odbc' or – Przemek eS Jan 18 '17 at 08:16
  • 'hostname' => '10.140.0.22\BIG', 'username' => '000', 'password' => '****', 'database' => 'se', 'dbdriver' => 'sqlsrv', 'dbprefix' => 'sd_', 'pconnect' => FALSE, 'db_debug' => (ENVIRONMENT !== 'production'), 'cache_on' => FALSE, 'cachedir' => '', 'char_set' => 'utf8', 'dbcollat' => 'utf8_general_ci', 'swap_pre' => '', 'encrypt' => FALSE, 'compress' => FALSE, 'stricton' => FALSE, 'failover' => array(), 'save_queries' => TRUE – M.Ghavam Jan 18 '17 at 21:55
-2

The error you are showing for the SQLSRV driver implies the DLL is never loading. What does your php_info() say?.

Also, do you have the SQL Server Native Access Client (SNAC) 10 installed? The SQLSRV driver requires it.

CodeIgniter's built-in ODBC driver, which adds apostrophes around the table names. I had a quick look through odbc_driver.php, changed the way tables are referenced and that solved the issue

//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';