How to insert Hebrew value in mysql db in php

I am trying to insert a hebrew value in my mysql db, instead of hebrew the values ​​look like this.

Γ— Β© Γ— "Γ— Β© Γ—" Γ—> Γ— Β’ Γ— Β© Γ— "

The default latin1_swedish_ci table mapping, I also tried changing to utf-8_general_ci, hebrew_bin, hebrew_general_ci, but the result is still the same.

In my code, I use, of course, a meta tag to configure the encoding:

<meta charset="UTF-8"> 

And before my php request, I added this line:

 mysql_query("SET NAMES utf8"); 

I am viewing the result in phpmyadmin.

+4
source share
8 answers

Check collation_connection connection:

 show variables like '%collation%' 
+1
source

I solved my problem in Hebrew. This was a problem with the encoding of the database and table / field. Here is the solution I used. I got help from another answer, and the link is below, in case someone needs it.

  • The db mapping should be utf8_general_ci .
  • Hebrew table mapping should be utf8_general_ci
  • in my php connection script i put header('Content-Type: text/html; charset=utf-8');
  • in my xhtml head tag I put <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  • after selecting db in the connection script i put mysql_query("SET NAMES 'utf8'");

and then the problem was resolved.

The first answer helped me and I took it from there

+14
source

Set encoding to achieve a solution

When creating a database

 CREATE DATABASE db_name CHARACTER SET utf8 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT COLLATE utf8_general_ci ; 

Or if the database is already created

 CREATE TABLE table_name( ... ) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; 

OR when writing a request

 mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'", $conn); $re = mysql_query('SHOW VARIABLES LIKE "%character_set%";')or die(mysql_error()); while ($r = mysql_fetch_assoc($re)) {var_dump ($r); echo "<br />";} 
+4
source

You must ensure that:

  • you install utf-8 in php
  • you are using utf-8 in connection
  • Your table is defined as utf-8_general_ci
  • a specific field is defined as utf-8_general_ci

Then you should be able to properly view Hebrew or any other language in phpadmin

+1
source

I would say to make sure that the values ​​are well transferred to the database, I would add a stamp statue before inserting into the database and print the value, for example:

 die($_POST['thevalue']); //insert to database. //... 

If everything goes well, the problem arises on the database side, in the database I would try with this mapping

| Hebrew | ISO 8859-8 Hebrew | hebrew_general_ci | 1 |

according to http://dev.mysql.com/doc/refman/5.0/en/charset-mysql.html .

But if this is a failure on the php side, the reason may be that the server does not support Hebrew, make sure that you use the correct meta tag on the html output document with

 ... <meta charset="ISO 8859-8"> ... 

Let's find out how this happens, good luck :)

0
source

I agree that it is installed as a utf-8 option, however if for some reason you cannot, then you can always convert to base64. Not the best (long way), but it can help someone from the pit.

0
source

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

  • The database value ( all of this ) should be utf8_general_ci .
  • Set table mapping to Hebrew also utf8_general_ci .
  • In the HTML "head" tag, add the following: <meta charset = "utf-8">
  • In your PHP connection file, add after the connection. Request this line: conn-> exec ("set names utf8");
  • If you use classes, then you will probably have "conn" as a variable. in this case you will have to use it as follows: $ this-> conn-> exec ("set names utf8");

Hope this helps future people who have this problem and using PDO. Good luck.

0
source

which ultimately helped me - add an encoding to the connection:

 {"mysql:host=$host;dbname=$db;charset=utf8"} 
0
source

Source: https://habr.com/ru/post/1483579/


All Articles