-1

Have a problem doing select queries on our MySql database.

This query is working fine:

SELECT name FROM products WHERE brand = 'nike'

This one doesn't:

SELECT name FROM products WHERE brand = 'tøj'

There are 1,000+ products with brand = 'tøj', so I guess the problem is related to the non-english character.

Strange thing is that it's only when running the query via Wordpress/PHP that things doesn't work. If I run SELECT name FROM products WHERE brand = 'tøj' through SQLYog, I get the results that I expect.

Does anyone know how to fix this?

Thanks!

Louisa
  • 552
  • 1
  • 9
  • 22
  • 2
    charset / collation of database / table / column; connection? – Drew Oct 15 '16 at 23:19
  • Also does product has ? instead of ø in brand column? – eg04lt3r Oct 15 '16 at 23:25
  • Try changing your table to UTF-8 and/or your text editor. – user3502626 Oct 15 '16 at 23:26
  • see this for starters http://dev.mysql.com/doc/refman/5.7/en/charset-column.html then see **Section2 / What does Show your Schema Mean?** of [What is Sqlfiddle and why should I care?](http://stackoverflow.com/a/38899465) to help us to help you :p – Drew Oct 15 '16 at 23:27
  • Database/table is utf8/utf8_general_ci. Product has "ø" in the brand column. – Louisa Oct 16 '16 at 22:04

2 Answers2

0

Specify character settings per database. To create a database such that its tables will use a given default character set and collation for data storage, use a CREATE DATABASE statement like this:

CREATE DATABASE mydb
  DEFAULT CHARACTER SET utf8
  DEFAULT COLLATE utf8_general_ci;

Tables created in the database will use utf8 and utf8_general_ci by default for any character columns.

Specify character settings at server startup. To select a character set and collation at server startup, use the --character-set-server and --collation-server options. For example, to specify the options in an option file, include these lines:

[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
Hitesh Vala Ahir
  • 773
  • 2
  • 13
  • 27
  • Thanks. The database is already running the mentioned character set and collation. Where do I set the character settings for the server startup? – Louisa Oct 15 '16 at 23:40
0

Fixed it by converting the "ø" to "ø" (based on http://www.i18nqa.com/debug/utf8-debug.html)

i.e. SELECT name FROM products WHERE brand = 'tøj' instead of SELECT name FROM products WHERE brand = 'tøj'

Louisa
  • 552
  • 1
  • 9
  • 22