SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2010
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Where condition returns empty resultset for utf-8 chars

    Hi All,
    I have created mysql table which has a text field, varchar and both are in utf-8 format. But When I do select query with where condition it returns empty result set even it has a value.
    I make the field as utf-8 format, table as utf-8 format. What should I do for this problem

  2. #2
    SitePoint Wizard guelphdad's Avatar
    Join Date
    Oct 2003
    Location
    St. Catharines, ON Canada
    Posts
    1,708
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    are you using the mysql client or a GUI for this or are you using a front end like PHP and perhaps introducing the error there?

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2010
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm using php it doesn't show any error message. It just return an empty string.

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Most likely, one of the values(either value in db, or val in the sql query) is not really utf8, or it may have some additional characters that you can't visually detect.

    Take a close look at the values. This should help make the difference more obvious.
    Code:
    select HEX(name), HEX('$name'), 
           LENGTH(name), LENGTH('$name'), 
           CHAR_LENGTH(name), CHAR_LENGTH('$name'), 
           name, '$name'
    from sometable

  5. #5
    SitePoint Wizard guelphdad's Avatar
    Join Date
    Oct 2003
    Location
    St. Catharines, ON Canada
    Posts
    1,708
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    are you using phpmyadmin or php in a script? if the latter, what error checking? Do you have access to the mysql client to check if your query should return rows?

    can you show some sample rows in the table, which of those rows should be returned by the query and the query itself?

  6. #6
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,029
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    If you are using php to connect to MySQL, right after you establish a connection to the MySQL server but before you select a database if using the mysql_* extension:

    PHP Code:
    mysql_set_charset('utf8',$connection_identifier); 
    if using the mysqli_* extension:

    PHP Code:
    mysqli_set_charset ($connection_identifier,'utf8'
    That will tell PHP what character set you wish to use for the connection to the MySQL server.
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •