在具有附加绑定值的db2查询上获取无效的参数标记

时间:2018-09-28 14:44:35

标签: php mysql sql db2

我有一个php脚本,我正在其中执行一些PDO语句,直到现在一切都在工作。

我最近将sg.group_code as group_code添加到了我的第一个选择中,将其绑定为我的值之一,并在另一个选择中使用了它,但是问题是,我现在收到一条错误消息,“使用参数标记为NULL无效”

现在,如果我从第一选择,绑定值和第二选择中删除了group_code,那么它可以正常工作。另外,手动运行带有值的第二选择还可以。

通过添加一个值我在做什么错了?

<?php

$selectPlacements = "
    SELECT DISTINCT
        sku_id, s.frame as frame, sg.group_code as group_code, s.cover1 as cover, s.color1 as color, dealer_id
    FROM placements p
    inner join skus s 
    on p.sku_id = s.id
    inner join sku_groups sg 
    on sg.id = s.sku_group_id
    where p.expire_date > curdate()
    limit 100
    ;
";

try {
    $placementCheck = $MysqlConn->prepare($selectPlacements);
    $detailRslt = $placementCheck->execute();

     while ($placementRow = $placementCheck->fetch(PDO::FETCH_ASSOC)) {

        print_r($placementRow); //This prints the array I need that gets the parameters below

        $salesValues = [
        ":dealer_id" => $placementRow["dealer_id"],
        ":frame" => $placementRow["frame"],
        ":cover" => $placementRow["cover"],
        ":color" => $placementRow["color"],
        "group_code" => $placementRow["group_code"],
        ];



        $checkSales = "
            SELECT
                count(*) as sales_180,
                180/count(*) as velocity,
                :group_code,
                c.xslsno as salesNum,
                cr.slsupr as VP

            FROM groupSales g
                inner join customers c
                    on g.cstnoc = c.xcstno

                inner join customerReports cr
                    on c.xslsno = cr.xslsno
            WHERE g.cstnoc = :dealer_id
                AND g.framec = :frame
                AND g.covr1c = :cover
                AND g.colr1c = :color
                AND date(substr(g.extd1d,1,4)||'-'||substr(g.EXTD1d,5,2)||'-'||substr(g.EXTD1d,7,2) ) between current_Date - 180 DAY AND current_Date
                GROUP BY c.xslsno, cr.slsupr
        ";

        try{    
            $salesCheck = $DB2conn->prepare($checkSales);
            $salesResult = $salesCheck->execute($salesValues);


        }catch(PDOException $ex) {
            echo "QUERY TWO FAILED!: " .$ex->getMessage(); 
        }
    }

}catch(PDOException $ex) {
    echo "QUERY ONE FAILED!: " .$ex->getMessage();
}

?>

0 个答案:

没有答案