HEX
Server: Apache
System: Linux b:u:marcbase:1 3.10.0-1160.31.1.el7.x86_64 #1 SMP Thu Jun 10 13:32:12 UTC 2021 x86_64
User: apache (92344)
PHP: 7.0.18
Disabled: apache_get_modules, apache_get_version, apache_reset_timeout, apache_getenv, apache_note, apache_setenv
Upload Files
File: /var/www/html/marcbase.com.br/web/android_connect/get_all_products.php
<?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);

}

?>