1
我想用PHP检索SQL Server中的中文数据存储。我如何做到这一点,因为我试着用下面的代码,但它不工作。它只是返回???????????使用PHP从SQL Server中检索中文数据?
我的代码:
$query = "SELECT
[name]
,[venue]
FROM tablename
WHERE id = '2'";
/**********************************************/
//Just for the Purpose of Count Number of Rows
$params = array();
$options = array("Scrollable" => SQLSRV_CURSOR_KEYSET);
/******************************/
#Query the database to get the user details.
$res = sqlsrv_query($conn, $query, $params, $options);
$arr = array();
#If no data was returned, check for any SQL errors
if ($res == false)
{
echo 'Query not Executed : '. die(print_r(sqlsrv_errors(), TRUE));
}
else
{
while($obj = sqlsrv_fetch_array($res, SQLSRV_FETCH_ASSOC))
{
$arr[] = array(
"name" => $obj['name'],
"venue" => $obj['venue']
);
}
}
header('Content-type: application/json; charset=utf-8');
#Output the JSON data
echo json_encode($arr);
exit();
sqlsrv_free_stmt($res); // Closes a statement. Frees all resources associated.
sqlsrv_close($conn); // Closes a connection. Frees all resources associated.
我的数据库表结构:
您必须将Column数据类型设置为NVARCHAR才能在SQL SERVER中支持多语言。 –
** @ Paresh J **是的,我正在使用NVARCHAR。 – Mediasoft
你可以显示你的表格结构吗? –