SQLSTATE[42S02]:未找到基表或视图:1146 表“demostore.ps_bids”不存在

问题描述 投票:0回答:1

我创建了一个 updatebids.php,在这种情况下,如果一定数量的用户共享相同的赌注,则必须更新为 1 额外的欧元/美元。在图中,即使是同一个用户也可以下注相同的金额:/

enter image description here enter image description here 这里是查询

 UPDATE {$dbPrefix}auction_bid_details AS b1
                JOIN (
                    SELECT id_bid, bid_price, id_customer, 
                           RANK() OVER (PARTITION BY id_customer, id_bid, bid_price ORDER BY id_bid) AS rank
                    FROM {$dbPrefix}auction_bid_details
                ) AS ranked_bids
                ON b1.id_bid = ranked_bids.id_bid
                SET b1.bid_price = b1.bid_price + 1
                WHERE ranked_bids.rank > 1

这是使用该功能时的日志,没有错误 atm :

    /*
  0: "update_bids.php script started."
​​
1: "Attempting database connection.. Array .  <<<<<<<<<<<<<<<<<<<"
​​
2: "Database connection established.   . >>>>>>>>>>>>>>>>>>>>"
​​
3: "Starting bid update process..."
​​
4: "Bids updated successfully!"
​​
5: "update_bids.php script ended."
​​
length: 6
    */
        

smarty 中的前端,将在其中处理输入。正在使用Ajax

    
    
                // Perform the AJAX request
                $.ajax({
                    url: '/update_bids.php',
                    method: 'POST',
                    data: {
                        bid_amount: bidAmount,
                        auction_id: auctionId,
                        customer_id: customerId
                    },
                    success: function(response) {
                        // Log the response for debugging
                         console.log("Auction ID:", auctionId, "Customer ID:", customerId, "Bid Amount:", bidAmount);
    
                        // Optionally, update the page or show a success message
                        // $('.wk-success').html('<p>Bid submitted successfully!</p>');
                    },
                    error: function(xhr, status, error) {
                        // Log the error for debugging, i think this one is being fired :(
                        console.error(xhr.responseText);
    
                     }
   

php sql prestashop smarty
1个回答
0
投票

这似乎可以解决问题,可以处理并行请求并更新出价:

 $sql = "UPDATE {$dbPrefix}auction_bid_details AS b1
                JOIN (
                    SELECT id_bid, bid_price, id_customer, automatic_bid_price, 
                           RANK() OVER (PARTITION BY id_customer, id_bid, bid_price ,automatic_bid_price ORDER BY id_bid) AS rank
                    FROM {$dbPrefix}auction_bid_details
                ) AS ranked_bids
                ON b1.id_bid = ranked_bids.id_bid
                SET b1.automatic_bid_price = b1.automatic_bid_price + 1  
                WHERE ranked_bids.rank > 1
          "  ;




 try {
            // Begin the transaction
            $db->beginTransaction();

            // Lock the table
            $lockSql = "LOCK TABLES {$dbPrefix}auction_bid_details WRITE";
            $db->exec($lockSql);

            // Execute the update query
            $stmt = $db->prepare($sql);
            if ($stmt->execute()) {
                customLog("Bids updated successfully!");
            } else {
                customLog("Error updating bids: " . implode(", ", $stmt->errorInfo()));
                customLog($sql);
            }

            // Unlock the table
            $unlockSql = "UNLOCK TABLES";
            $db->exec($unlockSql);

            // Commit the transaction
            $db->commit();

        } catch (PDOException $e) {
            // Rollback the transaction in case of error
            $db->rollBack();
            customLog("SQL Error: " . $e->getMessage());
        }
© www.soinside.com 2019 - 2024. All rights reserved.