多个查询mysli

时间:2018-06-16 11:38:51

标签: php mysql

我正在尝试使用JSON获取连接结果,但我还要对数据库字段进行内部联接:

$query = "SELECT products.*, categories.categories_name FROM products INNER JOIN categories on products.idCategory=categories.id";
//creating a query
$query .= "SELECT id, product_name,  idCategory, url FROM products;";

$stmt = mysqli_multi_query($conn, $query);

//executing the query 
$stmt->execute();  // I get this error : "Call to a member function execute() on boolean"

//binding results to the query 
$stmt->bind_result($id, $product_name, $categories_name, $url);

$products = array(); 

//traversing through all the result 
while($stmt->fetch()){
    $temp = array();
    $temp['id'] = $id; 
    $temp['name'] = $product_name; 
    $temp['image'] = $url;
    $temp['phone'] = $categories_name;
    array_push($products, $temp);
}
echo json_encode($products);

0 个答案:

没有答案