Welcome Guest, Not a member yet? Register   Sign In
Diacritical marks are truncated via Active Record
#1

(This post was last modified: 11-24-2014, 08:22 AM by marksalvatore.)

A string containing a diacritical mark (ex, "Erlösten"), is getting truncated to "Erl" when stored in the database via Active Record.

     $values['name'] = "Erlösten";
     $this->db->insert($this->_table, $values);

will store the 'name' value as "Erl".
The 'name' field in the database is set as varchar(100) with encoding set to  'UTF-8 Unicode'.

Is there a configuration setting I've overlooked?
Reply
#2

If I don't use active record to insert the data, the full string is stored properly, so that suggests the problem might be in how active record is inserting the data. Could this be a bug in CI's implementation of active record? or maybe  just a configuration adjustment on my side?
Reply
#3

(This post was last modified: 11-24-2014, 11:42 AM by Rufnex.)

This must be a charset problem. Have you checked that your database connection is utf8, that your files (controller, views, etc.) are saved as uft8? And in your /application/config/database.php should be also the utf8 :

Code:
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',

And your database should have this encoding: utf8_general_ci

Reply
#4

I agree, that this has got to be a charset problem, however all is already set to utf8. The database config file contains those exact values. The encoding for the database field is utf8 with collation set to "utf8_general_c"i. And the default file encoding in my IDE is, and has always been set to utf8.

What about the database driver? Wouldn't that need to be utf8 as well? Any idea how to check that?
Reply
#5

Hm strange, do you connect with mysql, mysqli or pdo?

Reply
#6

I connect with mysqli.
Reply
#7

(This post was last modified: 11-25-2014, 06:52 PM by marksalvatore.)

So the diacritical marks truncate the 'name' string when using this db call:

$values['name'] = "Erlösten";
$this->db->insert($this->_table, $values);

And with this db call:

$sql = "UPDATE tblNames SET name='Erlösten' WHERE key = '$key'";
$this->db->query($sql);

But not when I use this db call:

$sql = "UPDATE tblNames SET name='Erlösten' WHERE key = '$key'";
$conn = new mysqli($hostname, $username, $password, $database);
$conn->query($sql);

Any ideas why?
Whether it's UPDATE or INSERT doesn't make a difference. The same result is produced by both in all three cases.
Reply
#8

Hm still strange. Have double checked your database if it has the correct encoding. On some servers i have seen, that if you create a database with utf8 its been created with latin1_swedish_ci. For that you have to turn it back to utf8 .. so not only the fields of a table should have utf8 also the database itself.

Finaly you can the this config without dbcollat

PHP Code:
'char_set' => 'utf8',
    
'dbcollat' => ''

Reply
#9

Unfortunately, I verified that my database is also set to encoding = "utf8". And I tried your suggestion of 'dbcollat' => '', but that didn't make a difference either. Could this be a legitimate bug?
Reply
#10

I think this should be not a bug. But we should figure this out. Can you tell us about your environment (server os, db version, php version, etc.) .. and CI 2 or 3?

Reply




Theme © iAndrew 2016 - Forum software by © MyBB