-1

跟随功能不起作用

public function matchingService() {

    $stmt = mysqli_prepare($this->connection, "
    INSERT INTO reusematching.matchedtable(user_idUser, productDetail_idProduct,Status,applyData)
        SELECT  waitinglist_user.user_idUser, 
                waitinglist_product.ProductDetail_idProduct, 
                productstatus,          
                waitinglist_user.waitinglistUser_applydata
                FROM reusematching.waitinglist_user, 
                reusematching.waitinglist_product, 
                productinformation.productdetail, 
                productinformation.productstatus
                where (waitinglistProduct_status = 1 
                and waitinglistUser_status = 1 
                and productCategroy_productCategroyID = waitinglistUser_applyProductType
                and ProductDetail_idProduct = idProduct
                and idStatus = waitinglistProduct_status);

    SET SQL_SAFE_UPDATES=0; 

    DELETE FROM reusematching.waitinglist_user
    WHERE Exists
                    (SELECT matchedtable.idMatchedTable
                        FROM  reusematching.matchedtable 
                        where  matchedtable.user_iduser= waitinglist_user.user_idUser);

    DELETE FROM reusematching.waitinglist_product
    WHERE Exists
                    (SELECT matchedtable.idMatchedTable
                        FROM  reusematching.matchedtable 
                        where  matchedtable.ProductDetail_idProduct
                                = waitinglist_product.ProductDetail_idProduct);

    SET SQL_SAFE_UPDATES=1;

    "); 

    $this->throwExceptionOnError();

    mysqli_stmt_execute($stmt);
    $this->throwExceptionOnError();


    mysqli_stmt_free_result($stmt);
    mysqli_close($this->connection);


    return null;
}

显示的弹性

服务器错误 MySQL 错误 - 1064:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 18 行的 'DELETE FROM reusematching.waitinglist_user WHERE Exists (SELECT matche' 附近使用正确的语法

为什么我有这个错误?以及如何调试它。

4

1 回答 1

0

PHP 中的 mysql 驱动程序不允许在单个 query() 调用中发出多个查询。旧的 mysql 和新的 mysqli 函数都是如此。这是一种防止某些形式的 SQL 注入攻击的安全措施。

您必须将您可怕的大查询语句拆分为多个(较小)单独的查询:

a) INSERT ... SELECT
b) SET ...
c) DELETE ..
d) etc...
于 2012-09-10T17:00:31.067 回答