Update: SOLVED
I just inserted charset=utfmb4 in my connection string and it worked.
$pdo = new PDO("mysql:host=localhost;dbname=db_name;charset=utf8mb4", "db_user", "db_pass") phew!
Original Question:
I'm building a contextual reference word bank related to my work field. I have a form with three text fields, using it I keep record of certain English words and phrases and their contextual meaning in my native Odia language.
Input form 1."Context"
Input form 2."English Word"
Input form 3. "Oriya Word"
In the live server the Odia words (say, ସହର) gets inserted as ସହର
The character encoding/collation is set to "utf8mb4_general_ci" (same as my localhost, where the texts get inserted/displayed as intended)
I tried adding the line
<form action="insert.php" method="post" accept-charset="utf-8"> but it didn't help.
What's wrong?
insert.php
<?php /* Attempt MySQL server connection.*/ try{ $pdo = new PDO("mysql:host=localhost;dbname=my_db", "user_name", "passss"); // Set the PDO error mode to exception $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch(PDOException $e){ die("ERROR: Could not connect. " . $e->getMessage()); } // Attempt insert query execution try{ // Create prepared statement $sql = "INSERT INTO my_glossary (Domain, Keyword, Oriya_Meaning) VALUES (:Domain, :Keyword, :Oriya_Meaning)"; $stmt = $pdo->prepare($sql); // Bind parameters to statement $stmt->bindParam(':Domain', $_REQUEST['Domain']); $stmt->bindParam(':Keyword', $_REQUEST['Keyword']); $stmt->bindParam(':Oriya_Meaning', $_REQUEST['Oriya_Meaning']); // Execute the prepared statement $stmt->execute(); echo "Records inserted successfully."; } catch(PDOException $e){ die("ERROR: Could not able to execute $sql. " . $e->getMessage()); } // Close connection unset($pdo); ?> <html> <p><a href="backend.php">Add another</a><p> The "Oriya_Meaning" field value is supposed to be in Odia script.
show create table my_glossary; OUTPUT
CREATE TABLE `my_glossary` ( `Domain` varchar(255) DEFAULT NULL, `Keyword` varchar(2000) DEFAULT NULL, `Oriya_Meaning` varchar(2000) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci
show create table my_glossary;tell you? And how are you testing how the data gets saved to the DB? Are you sure it's not just a display problem when retrieving the data?show create table my_glossary;and show us the output by EDITING the output into your questioncreate tablecell, expand it and you should see more text