我的php没有使用json从mysql返回阿拉伯字符的值

时间:2014-08-24 18:08:51

标签: php mysql json

我有一个PHP文件,它从MySQL返回一个值:除了我尝试返回阿拉伯语值时,一切都没问题:结果显示为NULL。

我使用网址http://MyWebSite.com/Myphp.php?title =احمد

访问该网址

我的PHP文件:

<?php

$host = "localhost"; // Host name 
$username = "alomeeco_testdb"; // Mysql username 
$password = "AlkaabI157450"; // Mysql password 
$db_name = "alomeeco_testdb"; // Database name 
$tbl_name = "Notes"; // Table name 

// Connect to server and select databse.
mysql_connect($host, $username, $password)or die("cannot connect"); 
mysql_select_db($db_name)or die("cannot select DB");

// To protect MySQL injection (more detail about MySQL injection)
$mytitle = $_REQUEST['title'];
$mytitle = stripslashes($mytitle);
$mytitle = mysql_real_escape_string($mytitle);

$sql="SELECT * FROM $tbl_name WHERE title = '$mytitle'";

$result = mysql_query($sql);

// Mysql_num_row is counting table row
$count = mysql_num_rows($result);


$count = 0;
$items;

while($row = mysql_fetch_array($result)) {
    $item['userName'] = $row['userName'];
    $item['title'] = $row['title'];
    $item['comments'] = $row['comments'];
    $item['commentsTime'] = $row['commentsTime'];
    $item['commentsDate'] = $row['commentsDate'];
    $items[$count++] = $item;
}

echo json_encode($items);

?>

0 个答案:

没有答案