Reputation: 141
Well with the the asks from is quite high explanatory will only strengthen the question.
APP have a chat system which be late the HTML , send it to PHP with ajax , but the usurer try to insert some emoji (emotion) of your device in the database he gets: "???" as a message.
How can I change this so that receive some kind of code for each emotion and the site list according to the value of it?
Upvotes: 3
Views: 2509
Reputation: 142366
This is a character set issue, not just an emoji issue.
Use CHARACTER SET utf8mb4
throughout.
mysqli_set_charset
or PDO equivalent)<meta ... utf-8>
in the html header.Upvotes: 6
Reputation: 44363
I have this sinking feeling inside that you have a character set problem if you are using InnoDB.
When you connect to MySQL, run this query
select
A.variable_name,
A.variable_value global_value,
B.variable_value session_value
from
(
select * from information_schema.global_variables
where variable_name like 'collation%'
) A
inner join
(
select * from information_schema.session_variables
where variable_name like 'collation%'
) B
using (variable_name);
My guess is you are going to see a difference, especially with collation_connection.
My suggestion: Make the collation_connection for the session the same as the global value.
select A.variable_value,B.variable_value,C.variable_value
into @coll_conn,@coll_db,@coll_srvr from
(
select * from information_schema.global_variables
where variable_name like 'collation_connection'
) A,
(
select * from information_schema.global_variables
where variable_name like 'collation_database'
) B,
(
select * from information_schema.global_variables
where variable_name like 'collation_server'
) C;
set session collation_connection = @coll_conn;
set session collation_database = @coll_db;
set session collation_server = @coll_srvr;
You can then verify the change within your session by running the first query again.
GIVE IT A TRY !!!
NOTE: I am only suggesting this because a Developer approached me with this situation last week and I ran the same queries, showing him that the database was not at fault. The app was changing the collation in the session after authenticating.
Upvotes: 8