0

I set my database settings to be

MySQL charset: UTF-8 Unicode (utf8)

MySQL connection collation:    utf8_general_ci

and here is my module that inserts records in the database

<?php

    class userscoresmodule extends CI_Model{

        function __construct(){
            parent::__construct();
            $this->load->database();//Φορτώνει την βάση δεδομένων
        }

        function AddUserScore($userID,$userName,$score,$userLastname){
            $data=array('userID' => $userID,
                        'userName' => $userName,
                        'userLastname' => $userLastname,
                        'score' => $score);
            $this->db->insert('highscores', $data);
        }

        public function getAllScores(){ //Επιστρέφει τα προϊόντα
            $this->db->select('*');
            $this->db->from('highscores');
            $this->db->limit(10);
            $this->db->order_by("score", "desc"); 
            $query = $this->db->get();
          //$query = $this->db->get('highscores');
            return $query->result_array(); // Επιστρέφει το αποτέλεσμα με την μορφή array 
        }
    }
?>

The problem is that when it adds a record with greek characters in the database is like ????????. I read in some posts that I have to set my database on UTF-8 , have I to do something else on the module too?

user2853437
  • 750
  • 8
  • 27
Avraam Mavridis
  • 8,698
  • 19
  • 79
  • 133
  • 1
    Check out http://stackoverflow.com/questions/279170/utf-8-all-the-way-through – Pekka Oct 20 '13 at 03:26
  • Not tested! But try adding this `$this->db->simple_query('SET NAMES \'utf-8\'');` after `$this->load->database();` – tttony Oct 20 '13 at 03:28
  • hi check your table fields charset too is it utf-8 or not – umefarooq Oct 20 '13 at 04:27
  • I'd recommend trying the query directly via MySQL (or if you don't have terminal access, use the likes of PhpMyAdmin). This would help eliminate problems with PHP/CI. – Mark Oct 20 '13 at 09:10

1 Answers1

0

You can check same with given changes. Please change Collation to utf8_unicode_ci. May be it will work for you.

jagruti
  • 390
  • 2
  • 6