简体   繁体   English

PDO,检查WHERE子句中未通过的条件

[英]PDO, check which condition(s) do not passed in WHERE clause

Lets say that an user wants to edit his order in a online shop, but in the same time his order has being processed and the status of this order is set to "dispatched". 假设用户想在网上商店中编辑其订单,但是与此同时,他的订单已被处理,并且该订单的状态设置为“已分派”。 Of course he can't really know that, because the order data was loaded just a while before it was dispatched. 当然,他不能真正知道这一点,因为定单数据是在发送前不久加载的。 Now he can only get the message "Something went wrong..." 现在他只能收到消息“出了点问题...”

With a scenario like below, I can only send back to the user (via ajax) message that the order couldn't be updated (either the data wasn't changed or some of the values does not match in WHERE clause) : 在以下情况下,我只能(通过ajax)发送回用户消息:无法更新订单(数据没有更改,或者WHERE子句中的某些值不匹配):

   $edit_order = $this->db->prepare('UPDATE orders SET '.$some_fields_loop.' WHERE id=:order_id AND user_id=:user_id AND product_id=:product_id AND NOT status = :ready AND NOT archived = 1');

   $edit_order->bindValue( ... );

   $edit_order->execute();

   if ($edit_order->rowCount()) 
   {
       echo(json_encode(array('status'=>'success', 'msg'=>'Your order has just been updated'));
   } 
   else 
   {
       echo(json_encode(array('status'=>'error', 'msg'=>'Your order has not been updated'));
   }

But I want to be more specific and let him know what's happened exactly (and eventually modify the order DOM elements, based on ajax response). 但是我想更具体一些,让他确切知道发生了什么(并最终基于ajax响应修改DOM元素的顺序)。

The order_id is wrong, or user_id because his session has just expired and the session[ user_id ] doesn't match the order, or so on... and send back to the user corresponding message. order_id是错误的,或者是user_id,因为他的会话刚刚到期并且session [ user_id ]与订单不匹配,依此类推……然后将相应的消息发送回用户。

How do I do this in single query? 如何在单个查询中执行此操作? Is that even possible, or should I run each query with single WHERE clause seprately (what I would really like to avoid) ? 这是否有可能,还是我应该单独使用单个WHERE子句运行每个查询(我要避免的是什么)?

SELECT * FROM orders WHERE id=:order_id

首先,然后根据所需值验证结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM