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

后端 未结 8 1182
温柔的废话
温柔的废话 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 15:57

    For future use, if you have this issue and you are using PDO and not mysqli, you will need to do it like this:

    1. The Database (all of it) collation has to be utf8_general_ci.
    2. Set the collation of the table with Hebrew also to utf8_general_ci.
    3. In the HTML "head" tag, add this: < meta charset="utf-8" >
    4. In your PHP connection file, add after the connection Query this line: conn->exec("set names utf8");
    5. if you are using classes, then you will probably have the "conn" as a variable. in that case, you will have to use it like this: $this->conn->exec("set names utf8");

    Hope this helps to future people that have this problem and using PDO. Best of luck.

提交回复
热议问题