Home » Php » php – MySQL db question marks instead of hebrew characters..?

php – MySQL db question marks instead of hebrew characters..?

Posted by: admin July 12, 2020 Leave a comment

Questions:

I’m trying to build a shopping cart using PHP & MySQL.
my db in MySQL is utf8 and my table in the db is utf8,

How can I use Hebrew characters?

How to&Answers:

I was able to solve this by doing the following:

  1. the db collation has to be utf8_general_ci
  2. the collation of the table with hebrew has to be utf8_general_ci
  3. in your php connection script put header('Content-Type: text/html; charset=utf-8');
  4. in xhtml head tag put <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. after selecting the db in the connection script put mysql_query("SET NAMES 'utf8'");

Answer:

After a lot of work I found a solution that always works..:
without SET_NAMES.

In the conn.inc.php file, after you selected a database and connected to it, do this:

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

…and in the html always use charset utf-8;

That solved it for me. No need to use set_names(), which is ok but it annoyed the hell out of me.

Answer:

You can use the PDO in your code like this:

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

Make sure you include the single quotation marks around the ‘utf8’.

Answer:

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

SET NAMES utf8

Execute this query (e.g. mysql_query("SET NAMES utf8")) right after you connect and before you move any data.

More info

Answer:

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

Answer:

Where are the question marks showing up? It may be an encoding problem somewhere other than in the data base.

Answer:

To store non-ASCII characters in a database column, you need to define that 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

Answer:

In my case I created the DB from a dump, and this command solve it:

ALTER DATABASE <database_name> CHARACTER SET utf8 COLLATE utf8_unicode_ci;

Answer:

mysql_query('SET NAMES utf8') ….. Put this in Php