As I am all about PHP, I found this interesting to play around with, be forewarned though that there are WAY more to the below code than what is given, you have to insert certain security measures, you need to know how to start a session to grab the input data to search your database with, you need to understand PHP PDO (PHP Data Objects) and how to use the parameterized statements, you need to read up on how to sanitize your returned data and then so much more...
As a rough sketch, your PHP will look something like this -
<?php
$host = 'your_host';
$dbname = 'your_database';
$username = 'your_username';
$password = 'your_password';
try {
$pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
die("Error: " . $e->getMessage());
}
function getServerTime() {
$dt = new DateTime();
return "Server_Time: " . $dt->format('Y-m-d H:i:s');
}
function get_mobinfo($mobileno, $deviceid) {
$remark_dl = "";
$tData = "";
$getsql = "SELECT free_join.Associate_Name, free_join.Mobile_No FROM free_join WHERE free_join.Mobile_No = ?";
try {
$stmt = $pdo->prepare($getsql);
$stmt->execute([$mobileno]);
$result = $stmt->fetch(PDO::FETCH_ASSOC);
if ($result) {
$remark_dl = "Getting mobileinfo: $mobileno: " . json_encode($result);
$tData = json_encode($result);
} else {
$remark_dl = "Getting mobileinfo: $mobileno: Not found";
}
} catch (PDOException $e) {
die("Error: " . $e->getMessage());
}
$strSessionID = session_id();
$current_trackingid = create_trackingid($strSessionID);
return $tData;
}
function get_shopdata($mobile, $category) {
$tData = "";
$product_obj = array();
if ($category == "cat_toy") {
$getsql = "SELECT shop_product.slno AS SL_No, shop_product.productid AS Product_ID, shop_product.productname AS Product_Name, shop_product.price_mrp AS MRP, shop_product.price_offer AS Our_Price, shop_product.cat AS Category, shop_product.`status` AS Status FROM shop_product WHERE status ='Active'";
} else {
$getsql = "SELECT * from shop_product";
}
try {
$stmt = $pdo->query($getsql);
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
$product_obj["ProductArray"] = $result;
$getsql_cat = "SELECT * FROM shop_tag WHERE shop_tag.`status` = 'Active'";
$stmt = $pdo->query($getsql_cat);
$result_cat = $stmt->fetchAll(PDO::FETCH_ASSOC);
$product_obj["CatArray"] = $result_cat;
$getsql_wish = "SELECT * FROM wishlist WHERE wishlist.`status` = 'A' AND wishlist.usermobile = ? ORDER BY wishlist.slno ASC";
$stmt = $pdo->prepare($getsql_wish);
$stmt->execute([$mobile]);
$result_wish = $stmt->fetchAll(PDO::FETCH_ASSOC);
$product_obj["WishArray"] = $result_wish;
$tData = json_encode($product_obj);
} catch (PDOException $e) {
die("Error: " . $e->getMessage());
}
return $tData;
}
function save_wishlist($mobile, $fpid) {
$jdat = date("Y-m-d H:i:s");
$insrtlogin = "INSERT INTO wishlist(usermobile, productid, doj, status) VALUES(?, ?, ?, 'A')";
try {
$stmt = $pdo->prepare($insrtlogin);
$stmt->execute([$mobile, $fpid, $jdat]);
} catch (PDOException $e) {
die("Error: " . $e->getMessage());
}
return "datasave";
}
function GET_MAX_ID($tbl_name, $fld_name) {
$MAX_slno = 0;
$sql = "SELECT MAX($fld_name) FROM $tbl_name";
try {
$stmt = $pdo->query($sql);
$result = $stmt->fetch(PDO::FETCH_ASSOC);
if ($result) {
$tmxid = $result[0];
if ($tmxid == "") {
$MAX_slno = 1;
} else {
$MAX_slno = intval($tmxid) + 1;
}
}
} catch (PDOException $e) {
die("Error: " . $e->getMessage());
}
return $MAX_slno;
}
?>