Error connecting to SQL Server using Codeigniter

Asked

Viewed 1,484 times

5

I have an error when connecting the database in my Codeigniter project, I am 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

1 answer

1

$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) ;
  • Organize code in sublime to be readable, or any text editor or IDE you’re using.

  • 3

    Select the code and use the button { } to format.

  • or around the code

Browser other questions tagged

You are not signed in. Login or sign up in order to post.