How to insert an hebrew value into a mysql db in php

后端 未结 8 1111
温柔的废话
温柔的废话 2020-12-10 15:30

I\'m trying to insert an hebrew value into my mysql db, instead of hebrew the values looks like that.

שדגשדכעשד

8条回答
  •  囚心锁ツ
    2020-12-10 16:15

    I have solved my Hebrew language problem. It was a database and table row/field encoding issue. Here is the solution I used. I took help from another answer and the link is given below, in case anyone needs it.

    1. The database collation has to be utf8_general_ci.
    2. The collation of the table with Hebrew has to be utf8_general_ci.
    3. In the PHP connection script put

      header('Content-Type: text/html; charset=utf-8');
      
    4. In the xhtml head tag put

      
      
    5. If you are using MySQLi put this code in the connection script after selecting the database:

      mysql_query("SET NAMES 'utf8'");
      

      If you are using PDO, put

      $conn->query("SET NAMES 'utf8'");
      

    The first answer helped me and I took it from there

提交回复
热议问题