jborch
jborch

Reputation: 1136

mysql_query returns nothing when called with special characters (The danish characters: æøå)

I generate a mysql query from a form with a free text search field.
Something like:
SELECT ... FROM ... WHERE 'something' LIKE '%SEARCH%'

All this works fine and returns the valid rows when the search does not contain any special characters, like the danish characters ÆØÅ.

When these letters ARE used, the query returns no results, all though when i take the generated query string and plug it into phpMyAdmin i get exacly the result i want.

Thanks

Upvotes: 1

Views: 783

Answers (4)

TeoF
TeoF

Reputation: 21

Also we can use PHP variable and convert it before the select operation (supposing data base is ISOO-8859-2) .

Example:

// word with special characters 
$search='kötészeti'; 
// conversion to ISO
$search=iconv("UTF-8","ISO-8859-2", $search);   
// create search condition
$condition="SELECT ... FROM ... WHERE 'something' LIKE '%$search%'"; 
// apply query
mysql_query($condition); 

Upvotes: 0

Whatever Kitchen
Whatever Kitchen

Reputation: 700

add this line of code in your connection file...

mysql_set_charset("utf8", $db);

it is better for you to encode your data to UTF-8 before you pass it into query...

Upvotes: 1

GergelyPolonkai
GergelyPolonkai

Reputation: 6431

I think you have an encoding problem, maybe phpMyAdmin is using a different client encoding than your other client. SET NAMES 'encoding' should just do what you need, I think.

Upvotes: 0

Ondřej Doněk
Ondřej Doněk

Reputation: 529

I'm not using Danish but Czech but I think there are the same (at least by UTF8 implementation) - you must keep in mind used encoding (original server script, data tables self and also your database connection handler).

Upvotes: 0

Related Questions