Coding issues with Codeigniter and Sql Server using ODBC
Ok, this is a typical encoding problem between SQL Server and PHP. So I'll move on to chase:
I am using ODBC to connect to Sql Server 2012 database. Here is the database configuration:
$db['odbc']['hostname'] = 'Driver={SQL Server};Server=localhost;Database=siadcon;';
$db['odbc']['username'] = 'sa';
$db['odbc']['password'] = 'sa';
$db['odbc']['database'] = 'siadcon';
$db['odbc']['dbdriver'] = 'odbc';
$db['odbc']['dbprefix'] = '';
$db['odbc']['pconnect'] = FALSE;
$db['odbc']['db_debug'] = FALSE;
$db['odbc']['cache_on'] = FALSE;
$db['odbc']['cachedir'] = '';
$db['odbc']['char_set'] = 'utf8';
$db['odbc']['dbcollat'] = 'utf8_general_ci';
$db['odbc']['swap_pre'] = '';
I have a table ( TABLE
) that contains special characters in a field NAME
that is NVARCHAR(30)
. Data:
ID NAME
1 Marín
2 Other
My problem is when I make a simple query:
$this->db->where('ID', '1');
$query = $this->db->get('TABLE');
I get this:
["ID"]=> string(2) "1" ["NAME"]=> string(5) "Mar n"
I try to avoid using utf_encode/utf_decode
for every request, so I've tried a lot of things to get things set up correctly to get the correct encoding, but nothing works for me.
Any ideas?
EDIT:
Same problem when I try to do an insert from Codeigniter (using $this->db->insert
). I tried to insert "Tést" but I see "TÃ © st" in the SQLServer database.
source to share
No one has answered this question yet
Check out similar questions: