Encoding problems with Codeigniter and Sql Server using ODBC

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Encoding problems with Codeigniter and Sql Server using ODBC



Ok, this is the typical charset encoding problem between SQL Server and PHP. So I'll cut to the chase:



I'm using ODBC to connect to a 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) which contains special characters in the NAME field, which is a NVARCHAR(30). The data:


TABLE


NAME


NVARCHAR(30)


ID NAME
1 Marín
2 Other



My problem is when I do a simple query like:


$this->db->where('ID', '1');
$query = $this->db->get('TABLE');



I get this:


["ID"]=> string(2) "1" ["NAME"]=> string(5) "Mar�n"



I'm trying to avoid using utf_encode/utf_decode on every query, so I've tried a lot of things in order to properly configure things to get the correct encoding, but nothing seems to work for me.


utf_encode/utf_decode



Any ideas?



EDIT:



Same problem when I try to make an insert from Codeigniter (using $this->db->insert). I've tried to insert "Tést", but in the SQLServer database I see "Tést".


$this->db->insert





I'm giving up. I think I'm going to modify the ActiveRecord insert(), update(), get()... methods.
– Daniel Marín
Jul 22 '15 at 10:26





have you found a solution on that?
– sotoz
Feb 12 '16 at 15:07





I'm afraid not. I gave up.
– Daniel Marín
Feb 15 '16 at 9:01









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

make 2 or more post in bootsrap

Store custom data using WC_Cart add_to_cart() method in Woocommerce 3

React Native Navigation and navigating to another Screen problem