title: Mysql HEX function to decode multi-byte utf8
body: <p>MySQL uses a function HEX() which will convert a sequence of characters to hexidecimal representation. The only problem is that it assumes each character is two-bytes. This is fine for most cases, but with utf-8 there are sometimes characters that span more than 2-bytes.</p>
  
  <p>For example. 0xEFBFBD is the three byte character used to signal an encoding error. When I have two of these character one after the other in the DB (6 bytes in total), in a utf8 encoded table, and I try SELECT HEX(col1) FROM table ..., this comes out as 0xC3AFC2BFC2BD rather than 0xEFBFBD. If I select it using a query in php, and then convert is to hex within php, it comes through as the correct format.</p>
  
  <p>What would be the best is a function is MySql which can decode proper, multi-byte UTF8. I'm very surprised that it appears not to exists and would like to know if anyone else has found this to be the case also and possible work-arounds.</p>
  
  <p>The closest thing I've found to an answer in MySql is:
  <a href="http://forums.mysql.com/read.php?103,375304,375660" rel="nofollow">http://forums.mysql.com/read.php?103,375304,375660</a></p>
  
  <p>but this advice doesn't really help. I'll post a test case later if no one has any ideas off the top of their head.</p>