0

When i enter this code and call it from database it show the text as Question marks instead or letters, the are arabic letters , so UTF8 should work but i don't know whit won't now.

<?php
header("Content-Type: application/json; charset=UTF-8");

$server   = "";
$username = "";
$password = "";
$database = "";

$con = mysql_connect($server, $username, $password) or die ("Could not connect: " . mysql_error());
mysql_select_db($database, $con);

$sql = "SELECT * FROM events WHERE id='1' ";
$result = mysql_query($sql) or die ("Query error: " . mysql_error());

$records = array();

while($row = mysql_fetch_assoc($result)) {
    $records[] = $row;
}

mysql_close($con);

print_r($records);

?>

it shows this as result

Array
(
    [0] => Array
        (
            [id] => 1
            [event] => ????? ?????
            [speaker] => ???? ???????
            [area] => ???????
            [place] => ???? ??????
            [addr] => ??? ???? ????????
            [datefrom] => 2012-10-05
            [dateto] => 
            [timefrom] => 19:26:27
            [timeto] => 
        )

)
BiGHeaD
  • 15
  • 4

3 Answers3

0

Check that your database also uses UTF-8:

SHOW CREATE DATABASE `your_db_name`

How did you insert your data?

And also verify that your web server is well configured (to use UTF8).

mbarthelemy
  • 12,465
  • 4
  • 41
  • 43
0

You need to set utf8 collation on the column where you store utf8:

rowname varchar(100) COLLATE utf8_unicode_ci NOT NULL,

...and also the connection is important (see answer from Roger Ng)

Niko Sams
  • 4,304
  • 3
  • 25
  • 44
-1

Here is the code to set the connection between client and database to UTF-8

$con = mysql_connect($server, $username, $password) or die ("Could not connect: " . mysql_error());
mysql_select_db($database, $con);

mysql_query('SET NAMES utf8');
mysql_query('SET CHARACTER_SET_CLIENT=utf8');
mysql_query('SET CHARACTER_SET_RESULTS=utf8');

$sql = "SELECT * FROM events WHERE id='1' ";
$result = mysql_query($sql) or die ("Query error: " . mysql_error());

Put these codes before you start your SQL statement.

Roger Ng
  • 771
  • 11
  • 28