Mohd Atiq
Mohd Atiq

Reputation: 151

How to insert Hindi data into, and fetch the same data from, MySQL

I don't know how to insert Hindi data into a MySQL database and fetch the same data from the database using Codeigniter. Please guide me.

public function add_tag_description() // this is my controller name
    {
        $this->load->helper('form');
        $post = $this->input->post();
        $post['add_tag_description'] = $this->input->post('add_tag_description');
        unset($post['submit']);

        $this->load->model('Prediction_model', 'prediction');
        if($this->prediction->add_tag_description($post)) {
            $this->session->set_flashdata('feedback', 'Tag Description added successfully');
            $this->session->set_flashdata('feedback_class', 'alert-success');
        } else {
            $this->session->set_flashdata('feedback', 'Tag Description failed to add successfully, please try again');
            $this->session->set_flashdata('feedback_class', 'alert-danger');
        }
        $this->load->view('admin/add_tag');
    }

Model :

public function add_tag_description($post)
    {
         $add_tag_description = $post['add_tag_description'];
         $add_tag = array(
             'description'  => $add_tag_description
            );
         $this->db->insert('tag_description',$add_tag);
    }

Upvotes: 1

Views: 1130

Answers (2)

sheraz
sheraz

Reputation: 464

If you are facing a MySQL database issue, you should change the charset to utf8 and collate utf8_general_ci for the column you want to store Hindi data in. Try the below query to alter your table column.

ALTER TABLE `<table_name>` CHANGE `<field_name>` `<field_name>` VARCHAR(100) 
CHARSET utf8 COLLATE utf8_general_ci DEFAULT '' NOT NULL;

If you are having trouble while printing data on a view page, just add a meta tag in the page's header section, like the below code:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

Upvotes: 1

Master Arts
Master Arts

Reputation: 1

Run this query

ALTER TABLE `table_name` CHANGE `column_name` `column_name` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL;

Add this code inside head tag

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

Upvotes: 0

Related Questions