Welcome Guest, Not a member yet? Register   Sign In
Inserting special characters into the database
#1

Hello,
I want to insert special characters into the database with builder. For example:  ????
When I send a query these special characters ??? as added to the database. What can I do for it? I am using the utf8mb4 character set in the database. The problem is not in the database. The DB Builder neutralizes these characters.
Reply
#2

@mktek,

Please show us your code. This will give us a better idea how to help you solve your issue.
Reply
#3

Thank you for answering.

I created a form where users write messages. Special characters such as a smile are written in this form field with the mobile phone. Unfortunately, while these special characters are being written to the database, they are being disabled. I am using utf8mb4 as the database character set. There is no problem with the database. The problem is that the db-builder neutralizes these characters. I'm writing sample code.

You can try by typing special characters such as smile with your mobile phone where it says ****. Please see the picture. (Sorry about my bad English.)

PHP Code:
    //$mesaj_post = trim($this->request->getVar('mesaj_post'));    
    
$mesaj_post "smile **** smile";
        
    
$insert_data = array(
        
'mesaj' => $mesaj_post,
        
'time' => time()
    );

    
$builder $this->db->table('table');
    
$result $builder->insert($insert_data); 


Attached Files Thumbnail(s)
   
Reply
#4

@mktek,

What version of CI are you using? Is it up to date?

Have you tried using query binding (https://codeigniter.com/userguide3/datab...y-bindings) to see if that works better for you.
Reply
#5

Make sure your using character set utf8 and collation utf8_unicode_ci for the database.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#6

Finally I found the cause of the problem.

I made the necessary arrangements in the database. I used utf8mb4 as a character set. Database change was not enough.

The following changes were required in the Config / Database.php file:


PHP Code:
//Old value:
'charset'  => 'utf8',
'DBCollat' => 'utf8_unicode_ci',

//New value:
'charset'  => 'utf8mb4',
'DBCollat' => 'utf8mb4_unicode_ci'

Thanks @InsiteFX, @php_rocs
Reply
#7

@mktek,

Your welcome. I'm glad that I could assist.
Reply
#8

@mktek,

Glad that you got it solved.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB