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

后端 未结 8 1113
温柔的废话
温柔的废话 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

      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      
    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

    0 讨论(0)
  • 2020-12-10 16:15

    I think I figure it out: here's my code:

    $conn = mysqli_connect($dbserver,$dbuser,$dbpwd,$dbname);
    
    if (mysqli_connect_errno()){
        printf("Connection failed: %s\n" , mysqli_connect_errno());
        exit();
    }
    
    printf("Initial character set: %s\n", mysqli_character_set_name($conn));
    
    /* change character set to utf8 */
    if (!mysqli_set_charset($conn, "hebrew")) {
        printf("Error loading character set hebrew: %s\n", mysqli_error($conn));
        exit();
    } else {
        printf("Current character set: %s\n", mysqli_character_set_name($conn));
    }
    
    0 讨论(0)
提交回复
热议问题