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
你可以顯示你的表格結構嗎? –