Explaination about how this question is different from the exact duplicate specified by Mr. @deceze
=================================
The solution provided in the so called duplicate article uses UTF-8 only and that I am already using in the code specified below.
My question specifically talks about two things:
1. Collation : utf8_general_ci
2. Methodology: OOPS instead of PDO
My code given below already implements UTF-8 and I have mentioned that it is working fine.
My question is about Hindi that is being stored perfectly bu i donot understand how to fetch it with the same collation in OOPS approach.
=================================
using Google API, I have inserted some information in the database in hindi language. The column in mysql has data type as LONGTEXT and Collation as: utf8_general_ci
When I insert the values from frontend in PHP, data is store something like this:
पà¥à¤°à¤¶à¥à¤¨ १
At the same time, I am also saving the encrypted value of this hindi data through md5 as: md5($_POST['transliterateTextareaans'])
ON the show page, I have set head information as follows:
<meta charset="UTF-8">
And the the data in hindi is displayed accurately.
Now here issue arises.
I want to convert this data again to md5 value and cross check with the database encrypted value, but they are not matching. (Consider the scenario of storing username and passwords in hindi OR MCQs where correct answer is stored in encrypted form and while checking the candidate answer it needs to be compared).
Here is my code:
if(md5($_POST['ans']) == $_POST['hids'])
{
//correct
}
else
{
//wrong
}
I have gone through google and found that I should set the collation of select query but i donot know how to do it. Here is my select code:
if($ques=$mysqli->prepare("SELECT * FROM mytab WHERE sno=?"))
{
$ques->bind_param('i', intval($_SESSION['qlist']));
if($ques->execute())
{
$res=$ques->get_result();
$row=$res->fetch_assoc();
}
}
The code has now been updated as below:
if(!$conn->set_charset("utf8")) // SETS THE CHARACTERSET
echo $conn->error;
if(!$conn)
{
die("Connection failure: ". $conn->connect_error);
}
if($sql=$conn->prepare("INSERT INTO q_bank VALUES (?, ?, ?, ?, ?, ?, ?)"))
$sql->bind_param('sssssss', $p1, $p2, $p3, $p4, $p5, $p6, $p7);
$p1=........... //upto $p5
$p6=md5($_POST['txtbox']);
Similarly, now the select code to get the data:
if(!$mysqli->set_charset("utf8")) //SETS THE CHARACTERSET FOR FETCHING
echo $mysqli->error;
$ques->bind_param('i', intval($_SESSION['qlist'][$_SESSION['qnum']]));
Now, the data which doesnot have any digits in it, compares fine.
The data which has any digit in it, fails to compare.
Note: data here refers to the Option in an MCQ and it needs to be compared to the encrypted correct answer.