Error connecting to SQL Server using CodeIgniter

4

I'm having an error connecting the database to my CodeIgniter project, I'm using SQL Server.

$db['sql'] = array(
    'dsn'     => 'DRIVER={SQL Server}; SERVER=HOSTPT-01407; DATABASE=localidade;',
    'hostname' => 'HOSTPT-01407',
    'username' => 'user123',
    'password' => 'password',
    'database' => 'localidade',
    'dbdriver' => 'odbc',
    'dbprefix' => '',
    '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) ;

The error that appears is as follows:

**A Database Error Occurred**

Unable to connect to your database server using the provided settings.

Filename: C:\wamp\www\ProjetoGuiaFacil\system\database\DB_driver.php

Line Number: 124
    
asked by anonymous 06.10.2015 / 21:41

1 answer

0
$db['sql'] = array(
    'Database'     => 'DRIVER={SQL Server}; SERVER=HOSTPT-01407; DATABASE=localidade;',
    'hostname' => 'NomedoServidor/SQLEXPRESS',
    'username' => 'user123',
    'password' => 'password',
    'database' => 'localidade',
    'dbdriver' => 'sqlsrv', // alterando para SQL server
    'dbprefix' => '',
    'pconnect' => TRUE, // alterando para true, para connectar
    'db_debug' => TRUE, // tornando o debug ativo do banco de dados, para que em caso de erro, exiba a mensagem: "Ocorreu um erro no banco de dados"
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt'  => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE) ;
    
29.10.2015 / 18:01