繁体   English   中英

使用PHP连接到MySQL数据库

[英]Connecting to MySQL database using PHP

谁能帮我这个忙,这个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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM