Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

PHP SQL query returns no results whenever an extended character (e.g. ó or ú) is used

  • 10-01-2011 01:01AM
    #1
    Closed Accounts Posts: 4,001 ✭✭✭


    Hi all

    I hope someone can help me with this as I am finding it very confusing.

    I have a search form which works fine when I use normal English characters. However when I use Spanish characters no results are ever returned.

    For example, let's say I want to search for "Selección".

    The SQL I generate in PHP will look like this:

    [PHP]
    select * from table where (title like '%Selección%')
    [/PHP]

    If I run this SQL directly on the MySQL database it will return 1 result.

    However if I run it within PHP it will return no results.

    This is my code:

    [PHP]
    $query = "select * from table where (title like '%Selección%')";
    $result = mysql_query($query);
    [/PHP]

    As you can see, it's very simple.

    Do any of you have any ideas what could be causing this?

    Note I have tried adding the following but it makes no difference:

    [php]
    mysql_query("SET NAMES 'UTF8'");
    [/php]

    Thanks!


Comments

  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    Not sure if you'll need to set the encoding when you are querying data from PHP.

    [php]$DB->query("SET NAMES 'utf8'");[/php]

    http://www.shawnolson.net/a/946/unicode-data-with-php-5-and-mysql-41.html


  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    By the way I'm not so sure you can literally write encoded chars like that in the source. May have to escape it with the unicode. I'm not sure, I never done unicode in PHP.


  • Closed Accounts Posts: 4,001 ✭✭✭Mr. Loverman


    Fixed it.

    htmlentities - which I use to sanatise user input - was converting the extended characters into different characters...

    Thanks for the assistance.


Advertisement