我有一个包含4列的数据库(ID,名称,描述,价格),我用php文件标记它们除了返回null的价格列之外都有效,因为它有€作为字符,我试图使用:
设置utf-8编码 header('Content-type: text/plain; charset=utf-8');
mysqli_query('SET CHARACTER SET utf8');
但没有运气。
这是我的php文件:
<?php
header('Content-type: text/plain; charset=utf-8');
// Create connection
$con=mysqli_connect("localhost","xxx","xxx","xxx");
mysqli_query('SET CHARACTER SET utf8');
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = "SELECT * FROM prodotti";
if ($result = mysqli_query($con, $sql))
{
// If so, then create a results array and a temporary one
// to hold the data
$resultArray = array();
$tempArray = array();
// Loop through each row in the result set
while($row = $result->fetch_object())
{
// Add each row into our results array
$tempArray = $row;
array_push($resultArray, $tempArray);
}
// Finally, encode the array to JSON and output the results
echo json_encode($resultArray);
}
// Close connections
mysqli_close($result);
mysqli_close($con);
?>
为了显示正确的价格而不是null,我需要更改什么?
修改 价格列的类型为:VARCHAR(50) 我也试过TEXT但没有运气
编辑2
这是query show variables like '%charac%';
在数据库