[請益] 從PHP往SQL撈資料, 無法顯示中文
以下這是一段來自網路的Sample code, 試過很多種方法都無法顯示中文
1. 在PHP裡
echo '<meta http-equiv="Content-Type" content="text/html" charset="big5" />';
2. 在PHP外
<meta http-equiv="Content-Type" content="text/html" charset="big5" />
上述方法都試過用utf8來寫, 資料庫的編碼為"utf8_general_ci"
<?php
/*
* Following code will list all the products
*/
// array for JSON response
$response = array();
// include db connect class
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
// get all products from products table
$result = mysql_query("SELECT *FROM products") or die(mysql_error());
// check for empty result
if (mysql_num_rows($result) > 0) {
// looping through all results
// products node
$response["products"] = array();
while ($row = mysql_fetch_array($result)) {
// temp user array
$product = array();
$product["pid"] = $row["pid"];
$product["name"] = $row["name"];
$product["price"] = $row["price"];
$product["created_at"] = $row["created_at"];
$product["updated_at"] = $row["updated_at"];
// push single product into final response array
array_push($response["products"], $product);
}
// success
$response["success"] = 1;
// echoing JSON response
echo json_encode($response);
} else {
// no products found
$response["success"] = 0;
$response["message"] = "No products found";
// echo no users JSON
echo json_encode($response);
}
?>
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 163.21.79.182
→
12/10 18:02, , 1F
12/10 18:02, 1F
→
12/10 22:24, , 2F
12/10 22:24, 2F
→
12/10 23:19, , 3F
12/10 23:19, 3F
→
12/10 23:41, , 4F
12/10 23:41, 4F
→
12/10 23:42, , 5F
12/10 23:42, 5F
→
12/10 23:45, , 6F
12/10 23:45, 6F
→
12/10 23:45, , 7F
12/10 23:45, 7F
推
12/11 01:31, , 8F
12/11 01:31, 8F
→
12/11 11:54, , 9F
12/11 11:54, 9F
→
12/11 11:55, , 10F
12/11 11:55, 10F
→
12/11 12:53, , 11F
12/11 12:53, 11F
→
12/11 15:40, , 12F
12/11 15:40, 12F
PHP 近期熱門文章
PTT數位生活區 即時熱門文章