我用PHP写了一个API,但是我不能得到响应,早些时候我在另一个共享主机中使用了相同的API,但是当我把我的服务器改为另一个go-daddy共享主机时,一些API可以工作,但是其他的不工作。我不知道为什么会发生这种事。使用postman,当我回显数组长度作为响应时,它得到正确的数组长度为14(我的列计数),但没有显示结果。请帮我解决这个问题public function viewstock($token, $shopid)
{
$res = array();
$userId = $this->tokenVerification($token);
$delstatus = 0;
$ProductList = array();
$data = array();
if ($userId > 0) {
if ($stmt = $this->con->prepare("SELECT s.product_id,s.shop_id,s.product_category_id,s.display_order,s.sku,s.product_name,s.description,s.pro_type,s.is_timing,s.dateinfo,c.category_name,s.is_spe_offer,s.is_active FROM shop_stock s, category c WHERE s.product_category_id=c.id AND s.shop_id=? AND s.is_delete=?")) {
$stmt->bind_param("ii", $shopid, $delstatus);
$stmt->execute();
$stmt->bind_result($product_id, $sho_id, $category_id, $display_order, $sku, $product_name, $product_desc, $pro_type, $pro_availability, $dateinfo, $category_name, $is_offer, $is_active);
while ($stmt->fetch()) {
$temp = array();
$temp['product_id'] = $product_id;
$temp['shopid'] = $sho_id;
$temp['category_id'] = $category_id;
$temp['displayorder'] = $display_order;
$temp['sku'] = $sku;
$temp['product_name'] = $product_name;
$temp['product_desc'] = $product_desc;
$temp['pro_type'] = $pro_type;
$temp['pro_availability'] = $pro_availability;
$temp['dateinfo'] = $dateinfo;
$temp['product_category'] = $category_name;
$temp['is_offer'] = $is_offer;
$temp['pro_status'] = $is_active;
array_push($data, $temp);
}
/* free results */
$stmt->free_result();
/* close statement */
$stmt->close();
foreach ($data as &$value) {
$StockList = array();
$StockList = $value;
$stmt2 = $this->con->prepare("SELECT id,image,dateinfo FROM product_images WHERE product_id=? order by id");
$stmt2->bind_param("i", $value['product_id']);
$stmt2->execute();
$stmt2->bind_result($id, $image, $dateinfo);
$imagelist = array();
while ($stmt2->fetch()) {
$temp1 = array();
$temp1['image_id'] = $id;
$temp1['image'] = $image;
$temp1['dateinfo'] = $dateinfo;
array_push($imagelist, $temp1);
}
$StockList["imagelist"] = $imagelist;
$stmt3 = $this->con->prepare("SELECT p.id, p.variant_name as pro_variant,p.mrp,p.selling_price,p.offerpercent,p.stock_quantity,v.id,v.variant_name,p.stock_limit,p.unit FROM product_variant p, variants v WHERE p.variant_id=v.id AND p.product_id=?");
$stmt3->bind_param("i", $value['product_id']);
$stmt3->execute();
$stmt3->bind_result($id, $pro_variant, $mrp, $sellingprice, $offerpercent, $stock_quantity, $variant_id, $variant_name, $stock_limit, $unit);
$data2 = array();
while ($stmt3->fetch()) {
$temp5 = array();
$temp5['id'] = $id;
$temp5['pro_variant'] = $pro_variant;
$temp5['mrp'] = $mrp;
$temp5['selling_price'] = $sellingprice;
$temp5['offerpercent'] = $offerpercent;
$temp5['stock_quantity'] = $stock_quantity;
$temp5['variant_id'] = $variant_id;
$temp5['variant_name'] = $variant_name;
$temp5['stock_limit'] = $stock_limit;
$temp5['unit'] = $unit;
array_push($data2, $temp5);
if (!$temp5['stock_quantity'] == 0) {
$flag = 1;
}
}
$StockList["variantlist"] = $data2;
if ($flag == 1) {
array_push($ProductList, $StockList);
}
}
/* free results */
$stmt2->free_result();
/* close statement */
$stmt2->close();
/* free results */
$stmt3->free_result();
/* close statement */
$stmt3->close();
if (count($ProductList) <= 0) {
$res['st'] = 'no';
$res['data'] = 'No Data';
} else {
$res['st'] = 'yes';
$res['data'] = $ProductList;
}
return $res;
} else {
// $error = $mysqli->errno . ' ' . $mysqli->error;
// echo $error;
}
} else if ($userId == 0) {
//token verification expired
//echo "Expired";
$res['st'] = 'expire';
$res['data'] = 'No Data';
return $res;
}
}
这是一个不工作的API,使用MYSQL作为我的数据库。
当我使用pirnt_r()时,我可以获得响应,但是为什么它没有显示在我的响应中public function categorylist($token)
{
$res = array();
$userId = $this->tokenVerification($token);
$delstatus = 0;
$noparent = "None";
if ($userId > 0) {
$stmt = $this->con->prepare("SELECT p.id,p.category_name,p.display_order,p.dateinfo,IFNull((SELECT category_name from category WHERE p.parent_id=id),?)as parent,p.image FROM category p WHERE p.is_delete=? ORDER BY p.id DESC ");
$stmt->bind_param("si", $noparent, $delstatus);
$stmt->execute();
$stmt->bind_result($id, $category_name, $displayorder, $dateinfo, $parent, $image);
$CategoryList = array();
while ($stmt->fetch()) {
$temp = array();
$temp['category_id'] = $id;
$temp['main_name'] = $parent;
$temp['category_name'] = $category_name;
$temp['display_order'] = $displayorder;
$temp['dateinfo'] = $dateinfo;
$temp['image'] = $image;
array_push($CategoryList, $temp);
}
if (count($CategoryList) <= 0) {
$res['st'] = 'no';
$res['data'] = 'No Data';
} else {
$res['st'] = 'yes';
$res['data'] = $CategoryList;
}
/* free results */
$stmt->free_result();
/* close statement */
$stmt->close();
return $res;
} else if ($userId == 0) {
//token verification expired
//echo "Expired";
$res['st'] = 'expire';
$res['data'] = 'No Data';
return $res;
}
}
此代码正在工作,并从相同的服务器获得结果