有人能帮我吗,这个php
代码出了什么问题?
根据"http://phpcodechecker.com/":
Parse error: syntax error, unexpected '$response' (T_VARIABLE) in your code on line 7
$response["products"] = array();
get_all_products.php
<?php
$response = array();
require_once __DIR__ . '/db_connect.php';
$db = new DB_CONNECT();
$result = mysql_query("SELECT *FROM products") or die(mysql_error());
if (mysql_num_rows($result) > 0) {
$response["products"] = array();
while ($row = mysql_fetch_array($result)){
$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"];
array_push($response["products"], $product);
}
// success
$response["success"] = 1;
echo json_encode($response);
} else {
// no products found
$response["success"] = 0;
$response["message"] = "No products found";
echo json_encode($response);
}
?>
http://ua2.php.net/mysql_query
试试这样的东西:
$db = new DB_CONNECT();
$result = mysql_query("SELECT * FROM products", $db);