Hi everyone.

I want to store greek letters in mysql table my table collaction is utf8_general_ci and i'm calling this function after database connection

mysqli_query($connection, "SET NAMES 'utf8'");
mysqli_query($connection,"SET CHARACTER SET 'utf8'");

but all greek letters in database are like "??????? ???" Question mark how to resolve this ???

I search on internet and eveyone says set characterset that i also set even in my html page i also have this line
<meta http-equiv="content-type" content="text/html; charset=UTF-8">

someone says change utf8_general_ci to greek_general_ci but still have same problem

Regards
Rizwan

Dani AI

Generated

Quick summary and likely cause: seeing "????" for Greek text usually means an encoding mismatch between three places — the HTTP/page encoding, the PHP→MySQL client connection, and the table/column character set. The browser/meta tag alone may not be enough if the HTTP response header or the connection is wrong; all three must agree (modern recommendation: use utf8mb4). (developer.mozilla.org)

On the connection side (as hinted) set the client charset through the DB API rather than only issuing SQL after connect. For PHP, either set the charset in the PDO DSN or use the mysqli client API to set the connection charset before any queries. Example (PDO):

$pdo = new PDO(
  'mysql:host=localhost;dbname=yourdb;charset=utf8mb4',
  $user, $pass,
  [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
);

Setting the connection correctly avoids silent conversions/loss. (php.net)

Quick checks to run (mysql client or phpMyAdmin SQL tab) to locate the mismatch:

SELECT @@character_set_client, @@character_set_connection, @@character_set_results;
SHOW SESSION VARIABLES LIKE 'character_set%';
SHOW CREATE TABLE your_table\G
SELECT HEX(your_col) FROM your_table LIMIT 1;

If the session variables and the CREATE TABLE output disagree, the problem is the connection step or the column definition. Use the HEX() output to inspect stored bytes. (dev.mysql.com)

If columns are wrong, convert them to utf8mb4 and an appropriate collation; for example:

ALTER TABLE your_table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

If bytes were stored under the wrong charset but should be reinterpreted rather than converted, use the BLOB trick (change to BLOB then back to TEXT with the correct charset) as documented. If characters were replaced by literal question marks at insert time, that replacement is irreversible. Prefer utf8mb4 for new apps — MySQL documents utf8 (utf8mb3) is legacy and utf8mb4 is recommended. (dev.mysql.com)

Notes tied to the thread: 's suggestion to create columns with a Unicode charset is correct — confirm column-level charset (not just the database default) and ensure phpMyAdmin itself is using the right connection charset when inspecting rows.

Recommended Answers

All 3 Replies

Did you create your table like this?

CREATE TABLE t1
(
    col1 CHAR(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci
)

i attached the table image i haven't created the table with query i created in PHPmyAdmin table.JPG

mysqli_set_charset($connnection,"utf8");

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.