[英]Connecting to MySQL database using PHP
can anyone please help me with this, whats wrong with this php
code ? 谁能帮我这个忙,这个php
代码怎么了?
according to " http://phpcodechecker.com/ " : 根据“ http://phpcodechecker.com/ ”:
Parse error: syntax error, unexpected '$response' (T_VARIABLE) in your code on line 7 $response["products"] = array();
get_all_products.php 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 http://ua2.php.net/mysql_query
try something like this: 尝试这样的事情:
$db = new DB_CONNECT();
$result = mysql_query("SELECT * FROM products", $db);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.