1

When I run a query directly in MySQL using phpMyAdmin it allows (long dash, not normal -), but when I run this query from my PHP code, it turns them to –.

If you encode – it'll come %E2%80%93 (in JavaScript). %E2 becomes â, %80 becomes and %93 becomes . I don't understand when I run the query in phpMyAdmin it saves data as , but when I run the query in my PHP code, then it does not work in the way I want.

3 Answers 3

1

Which character encoding do you use in your table? After connecting to the DB in php try to run this:

mysql_query('SET NAMES utf8'); //if you use utf-8
Sign up to request clarification or add additional context in comments.

5 Comments

Do you mean Collation of the filed? It's "latin1_swedish_ci". BTW, your suggestion worked. Thank You very much!
@Debiprasad: Unless you are swdish, you should shwitch to utf-8. It makes life easier.
Even if you are swedish, a switch to UTF-8 won't hurt. :)
So you guys suggest to use this: DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci Thank you!
I modified my database, table and column to utf8, also removed mysql_query('SET NAMES utf8'); - now I can see now old issue. Earlier those are in "latin1_swedish_ci" and I added mysql_query('SET NAMES utf8'); to my code. Here I was not experiecing the issue. I need to learn more on this and will update about this here.
0

Maybe phpMyAdmin engine escapes long dash to normal dash ?

1 Comment

No, it does not escapes long dash to normal dash.
0

Probably you are missing to put the met tag on your HTML, have you write the next line in the head of your HTML document?

<meta http-equiv="content-type" content="text/html; charset=utf-8" />

Otherwise, the browser interprets it as ISO-8859-1.

You should use the same encoding everywhere, on your database, on your connection and on your html document.

For ensure you have a utf-8 table, run the next statement, and check it says CHARSET=utf8 almost at the end.

 SHOW CREATE TABLE tableName; 

2 Comments

No, this is not the problem. Thank you.
The query returns: DEFAULT CHARSET=latin1

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.