-1

I have an issue, i had a script to get some fields from a database and print em out but after some updates on the software something is wrong with UTF8 imo.

English is printed out just fine but for any greek i see ??????. Fields in the database are utf8_general_ci.

Below is the script

function getaffiliateclientname($inputid)
{
    $database="XXXXXXXX";
    mysql_connect ("XXXXXXXXXXXXXXXXXXX");
    @mysql_select_db($database) or die( "Unable to select database");


 $data = mysql_query("SELECT firstname, lastname FROM hb_client_details WHERE id = (SELECT client_id FROM hb_aff WHERE id=$inputid )") 
 or die(mysql_error()); 
 while($info = mysql_fetch_array( $data )) 
 { 
 return  $info['firstname'];

 } 
}

Any ides on what might be wrong?

LefterisL
  • 1,132
  • 3
  • 17
  • 37

1 Answers1

0

You want to tell mysql to use utf8 after connecting...like

<?php
// after connect
mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER SET 'utf8'");

Your website should send the correct charset to the browser before the output of the page begins:

<?php
     header('Content-type: text/html; charset=utf8');
     // echo $yoursite->render();

Regards

Jan.
  • 1,925
  • 15
  • 17
  • Was trying only the "mysql_query("SET NAMES 'utf8'");" at first. Put both of them in there worked like a charm. Thank you. – LefterisL Aug 20 '13 at 10:21
  • Don't `SET NAMES`! Use the `mysql_set_charset` API! See http://stackoverflow.com/a/12720360/476. – deceze Aug 20 '13 at 10:58