dongyong9224 2018-10-27 08:36
浏览 69

mysqli子查询与准备好的语句返回布尔值

so i prepared a query that already works in mysql(tested in phpmyadmin) but I have problem getting the results using mysqli class and its really weird not to get the results because I believe that the query is correct. Can anyone point out my mistake in the following code.

<?php

include_once __DIR__ . '/includes/init.php';

$sql = 'SELECT 
                    `purchase_order`.`id`, 
                    `purchase_order`.`po_date` AS po_date, 
                    `purchase_order`.`po_number`, 
                    `purchase_order`.`customer_id` AS customer_id , 
                    `customer`.`name` AS customer_name, 
                    `purchase_order`.`status` AS po_status, 
                    `purchase_order_items`.`product_id`, 
                    `purchase_order_items`.`po_item_name`, 
                    `product`.`weight` as product_weight,
                    `product`.`pending` as product_pending,
                    `product`.`company_owner` as company_owner,
                    `purchase_order_items`.`uom`, 
                    `purchase_order_items`.`po_item_type`, 
                    `purchase_order_items`.`order_sequence`, 
                    `purchase_order_items`.`pending_balance`, 
                    `purchase_order_items`.`quantity`, 
                    `purchase_order_items`.`notes`, 
                    `purchase_order_items`.`status` AS po_item_status,
                    `purchase_order_items`.`id` AS po_item_id
                  FROM (SELECT id, po_date, po_number, customer_id, status
            FROM purchase_order  GROUP BY  id   DESC  LIMIT ?, ? ) as purchase_order  
                  INNER JOIN customer ON `customer`.`id` = `purchase_order`.`customer_id`  
                  INNER JOIN purchase_order_items ON `purchase_order_items`.`po_id` = `purchase_order`.`id` 
                  INNER JOIN product ON `purchase_order_items`.`product_id` = `product`.`id` 
                   GROUP BY  id';

$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$statement = $mysqli->prepare($sql);
$statement->execute();
$offset = 0;
$perpage = 10;
$statement->bind_param('ii', $offset, $perpage);
$result = $statement->get_result();
while ($row = $result->fetch_assoc())
{
    echo '<pre>';
    print_r($row);
    echo '</pre>';
}

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • duan5991518 2018-10-27 08:41
    关注

    The sequence in which you prepare/bind and execute the statement and values is incorrect...

    $statement = $mysqli->prepare($sql);
    $offset = 0;
    $perpage = 10;
    $statement->bind_param('ii', $offset, $perpage);
    $statement->execute();
    

    You need to use bind_param() before the execute() so that it knows what values to use.

    评论

报告相同问题?

悬赏问题

  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错