PHP 1

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

<?

php
header('Content-Type: application/json');
$method = $_SERVER['REQUEST_METHOD'];
switch ($method) {
case 'GET':
loadProduct();
break;

default:
break;
}

function loadProduct()
{
$host="localhost";
$username="";
$password="";
$database="";
$conn = mysqli_connect($host,$username,$password,$database);

$payload = array();
$success = true;
$failed = false;

$query= "SELECT * FROM product";


$result = mysqli_query($conn, $query);
$status = mysqli_num_rows($result);

if ($status == 0)
{
$payload['status'] = $failed;
$payload['message'] = "No Product Found!";
}
else {

while ($row = mysqli_fetch_assoc($result)) {


$payload['status'] = $success;
$payload['message'] = "Data Loaded Successfully";
$payload['product'][] = $row;
}
}

echo json_encode($payload);
mysqli_close($conn);
}

You might also like