MySQL db question marks instead of Jewish characters ..?

I am trying to create a shopping cart using PHP and MySQL. my db in MySQL is utf8 and my table in db is utf8,

How can I use Hebrew characters?

+7
source share
8 answers

I was able to solve this by doing the following:

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

You can use PDO in your code as follows:

  $db = new PDO($config['DSN'], $config['dbUserName'], $config['dbPassword']); $db->exec("SET NAMES 'utf8'"); 

Make sure you include single quotes around "utf8".

+5
source

After much work, I found a solution that always works ..: without SET_NAMES.

In the conn.inc.php file conn.inc.php after you select the database and connect to it, do the following:

 if(!mysqli_set_charset($conn, 'utf8')) { echo 'the connection is not in utf8'; exit(); } 

... and in html always use charset utf-8;

This solved it for me. No need to use set_names() , which is good, but it annoyed me.

+5
source

If this is an encoding problem (and it looks like it is), this query will help:

 SET NAMES utf8 

Run this query (for example, mysql_query("SET NAMES utf8") ) immediately after connecting and before moving any data.

Additional Information

+3
source

Where do question marks appear? This may be a coding problem somewhere other than in the database.

+1
source

To save non-ASCII characters in a database column, you need to define this column with a specific character set. You can specify a character set at 3 levels: database, table, and column. For example:

 CREATE DATABASE db_name CHARACTER SET utf8 CREATE TABLE tbl_name (...) CHARACTER SET utf8 CREATE TABLE tbl_name (col_name CHAR(80) CHARACTER SET utf8, ...) 

http://www.herongyang.com/PHP/Non-ASCII-MySQL-Store-Non-ASCII-Character-in-Database.html

+1
source

$ conn-> set_charset ("utf8"); Use this for your dbconnect

+1
source

mysql_query('SET NAMES utf8') ..... put this in php

-one
source

All Articles