CRUD读取操作PHP

时间:2016-05-22 13:34:21

标签: php mysql mamp

我正在创建一个Android应用程序,需要从MAMP服务器上的MySQL数据库中检索信息。我编写了PHP代码来尝试从数据库中检索信息,但是没有从数据库中检索信息。我已经使用PHP代码检查器检查了代码,并且没有发现问题。任何人都可以找到任何问题或提供任何帮助链接。先感谢您。

<?php

/*
 * Following code will list all the products
 */

// array for JSON response
$response = array();

// include db connect class
 require_once('connect.php');

// connecting to db
//$db = new db_name();

// get all products from products table
$result = mysqli_query("SELECT * FROM tbl_book");

// check for empty result
if (mysqli_num_rows($result) > 0) {
    // looping through all results
    // book node
    $response["books"] = array();

    while ($row = mysqli_fetch_array($result)) {
        // temp user array
        $book = array();
        $book["id"] = $row["id"];
        $book["title"] = $row["title"];
        $book["description"] = $row["description"];
        $book["bookID"] = $row["bookID"];

        // push single book into final response array
        array_push($response["books"], $book);
    }
    // success
    $response["success"] = 1;

    // echoing JSON response
    echo json_encode($response);
} else {
    // no products found
    $response["success"] = 0;
    $response["message"] = "No book found";

    // echo no users JSON
    echo json_encode($response);
}
?>

0 个答案:

没有答案