当我收到以下错误消息时会出现什么错误
致命错误:带有消息'SQLSTATE [07002]的未捕获异常'PDOException':[Microsoft] [SQL Server的ODBC驱动程序11] COUNT字段不正确或语法错误'...
这是我正在使用的查询
$sql = $pdo->prepare("SELECT stockamount, stockname, stockbalance.stockid, SUM(ABS(reservationtransaction.stockquantity)) AS reservedamount FROM stockbalance JOIN stock ON stockbalance.stockid = stock.stockid LEFT JOIN reservationtransaction ON reservationtransaction.articleid = :artid WHERE stockbalance.articleid = :artid AND ((changeddate > DATEADD(yy,-1,GETDATE()) AND inventorydate > DATEADD(yy,-1,GETDATE())) OR stockbalance.stockamount <> 0) GROUP BY stockbalance.stockid"); $sql->bindValue(':artid', $productId); $sql->execute();
我在搜索过的问题,但没有人相似或有帮助.
提前致谢.
编辑:此查询在使用Microsoft SQL Server Management Studio执行时工作正常,但在使用PDO时,我收到错误.
SQLBindParameter中指定的参数数量小于*StatementText中包含的SQL语句中的参数数量.调用SQLBindParameter时,ParameterValuePtr设置为空指针,StrLen_or_IndPtr未设置为SQL_NULL_DATA或SQL_DATA_AT_EXEC,InputOutputType未设置为SQL_PARAM_OUTPUT,因此SQLBindParameter中指定的参数数量大于*StatementText中包含的SQL语句中的参数数量.SQLExecute函数
占位符必须具有唯一的名称,即使它们具有相同的值
$sql = $pdo->prepare("SELECT stockamount, stockname, stockbalance.stockid, SUM(ABS(reservationtransaction.stockquantity)) AS reservedamount FROM stockbalance JOIN stock ON stockbalance.stockid = stock.stockid LEFT JOIN reservationtransaction ON reservationtransaction.articleid = :artid WHERE stockbalance.articleid = :artid2 AND ((changeddate > DATEADD(yy,-1,GETDATE()) AND inventorydate > DATEADD(yy,-1,GETDATE())) OR stockbalance.stockamount <> 0) GROUP BY stockbalance.stockid"); $sql->bindValue(':artid', $productId); $sql->bindValue(':artid2', $productId); $sql->execute();