Save Data in Arabic in MySQL database

Viewed 114394

I have changed the charset of the tables and of the column, i get the arabic text as ???? marks in MYSQL database

here is the design of the table

  CREATE DATABASE mydb
  DEFAULT CHARACTER SET utf8
  DEFAULT COLLATE utf8_general_ci;


   CREATE TABLE `categories` (                        
   `category_id` tinyint(2) NOT NULL auto_increment,           
   `category_name` varchar(50)character set utf8 NOT NULL ,  
   PRIMARY KEY  (`category_id`) 


   insert into `mydb`.`categories` 
    (`category_id`, `category_name`)
    values (1,'کتگوری');
   commit;

When I again fire select query it shows ???? as text?

Can anyone tell me where am i doing wrong?

8 Answers

Try this code :

$conn = new mysqli($server,$username,$password,$dbname);
$conn->set_charset("UTF8");
CREATE TABLE mydb.categories         
(category_id tinyint(2) NOT NULL AUTO_INCREMENT
,category_name MEDIUMTEXT NOT NULL
,PRIMARY KEY (category_id)) DEFAULT CHARACTER SET utf8

Configuration configuration = new Configuration();

            // Hibernate settings equivalent to hibernate.cfg.xml  properties
            Properties settings = new Properties();
            
            settings.put(Environment.DRIVER, "com.mysql.cj.jdbc.Driver");
            settings.put(Environment.URL, "jdbc:mysql://localhost:3306/alizidan?useSSL=false&useUnicode=yes&characterEncoding=UTF-8");
            settings.put(Environment.USER, "root");
            settings.put(Environment.PASS, "");
            settings.put(Environment.DIALECT, "org.hibernate.dialect.MySQL5Dialect");
            // does not work with my sql settings.put(Environment.HBM2DDL_CHARSET_NAME, "UTF-8");

// characterEncoding=UTF-8 at "jdbc:mysql://localhost:3306/alizidan?useSSL=false&characterEncoding=UTF-8" work VERY GOOD

            settings.put(Environment.SHOW_SQL, "true");

            settings.put(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread");

    //        settings.put(Environment.HBM2DDL_AUTO, "create-drop");

            configuration.setProperties(settings);
Related