Reputation: 169
Simple question. With Codeigniter 2.x.x I had no problems in connecting to a MS SQLServer database. I have now upgraded to Codeigniter 3 and I get this error:
A Database Error Occurred
Unable to set client connection character set: utf8
Filename: core/CodeIgniter.php
Line Number: 500
Here is my database.php config file:
Codeigniter 2.x.x --> it works
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'XXX';
$db['default']['username'] = 'XXX';
$db['default']['password'] = 'XXX';
$db['default']['database'] = 'XXX';
$db['default']['dbdriver'] = 'mssql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$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 3 --> error
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => 'XXX',
'username' => 'XXX',
'password' => 'XXX',
'database' => 'XXX',
'dbdriver' => 'mssql',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
Any ideas? Thanks.
Further test include using the sqlsrv driver but I get this error:
A PHP Error was encountered
Severity: Runtime Notice
Message: Declaration of CI_DB_sqlsrv_driver::_limit() should be compatible with that of CI_DB_query_builder::_limit()
Filename: sqlsrv/sqlsrv_driver.php
Line Number: 459
A PHP Error was encountered
Severity: Runtime Notice
Message: Declaration of CI_DB_sqlsrv_driver::_delete() should be compatible with that of CI_DB_query_builder::_delete()
Filename: sqlsrv/sqlsrv_driver.php
Line Number: 459
A PHP Error was encountered
Severity: Runtime Notice
Message: Declaration of CI_DB_sqlsrv_driver::_update() should be compatible with that of CI_DB_driver::_update()
Filename: sqlsrv/sqlsrv_driver.php
Line Number: 459
Upvotes: 2
Views: 4184
Reputation: 33
update your DataBase.php config file to the below code :-
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => 'Driver={SQL Server Native Client 10.0};Server=XXX.XX.XXX.XXX;Database=myDataBaseName;',
'hostname' => '',
'username' => 'XXX',
'password' => 'XXX',
'database' => '',
'dbdriver' => 'odbc',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
Make Sure your db drivers are set to odbc like this 'dbdriver' => 'odbc'
Upvotes: 0
Reputation: 169
I ended up doing this:
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => 'Driver={SQL Server Native Client 10.0};Server=XXX.XX.XXX.XXX;Database=myDataBaseName;',
'hostname' => '',
'username' => 'XXX',
'password' => 'XXX',
'database' => '',
'dbdriver' => 'odbc',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
It works flawlessly. Thanks anyway for the tips.
Upvotes: 1