Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php mysql pdo拍卖招标_Php_Mysql_Pdo - Fatal编程技术网

php mysql pdo拍卖招标

php mysql pdo拍卖招标,php,mysql,pdo,Php,Mysql,Pdo,我正在使用PHPMYSQL(MyISAM)和PDO,使用两个表开发一个具有限制或最大出价场景的拍卖系统 拍卖 Id | title | seller | currentbid | limit(max bid) | dated | bidder 出价 Id | auctionid | bid | bidder | dated 用户出价后,会发生以下情况(我使用PDO准备的语句) $record=fetch('Select*from auction,其中id=:id'

我正在使用PHPMYSQL(MyISAM)和PDO,使用两个表开发一个具有限制或最大出价场景的拍卖系统

拍卖

 Id   | title | seller  |  currentbid   |  limit(max bid)   |  dated | bidder
出价

 Id  | auctionid | bid  | bidder | dated
用户出价后,会发生以下情况(我使用PDO准备的语句)

$record=fetch('Select*from auction,其中id=:id',array('id'=>$id))
$increment=1;
$postedBid=$_请求['postedBid'];
$currentBid=$record['currentBid'];
$limitBid=$record['limit'];
如果($postedBid<$currentBid+$increment){
返回;(不处理投标!)
}否则{
如果($limitBid!>$postedBid){
在投标书中插入(拍卖ID、投标书、投标人、日期(时间戳))价值($aucted、$postedBid、…);
更新拍卖集currentbid=$postedBid,limit=$postedBid…。
}否则{
在投标书中插入(拍卖ID、投标书、投标人、日期(时间戳))价值($aucted、$postedBid、…);
在标书中插入(拍卖ID、投标、投标人、日期(时间戳))值($aucted、$postedBid+$increment,…);
更新拍卖集currentbid=$postedBid+增量,限额=$limitBid…。
}
}
我想知道两件事

1-如果此方法可行,我如何改进

2-我如何避免同时投标。我不知道如何使用PDO应用锁。请欣赏使用锁或任何其他方法处理此问题的任何示例查询

谢谢


(很抱歉使用了混合类型的代码)

我认为在MySQL中的存储过程中,您需要做的是返回一条成功/失败消息

您需要将代码更改为以下内容:

If($postedBid < $currentBid + $increment){
   Return;(without processing bid!)
} else {
   $stmt = $db->prepare("CALL update_bid(?,?, ...)");
   $stmt->execute(array($parameter1, $parameter2, ...));
}
If($postedBid<$currentBid+$increment){
返回;(不处理投标!)
}否则{
$stmt=$db->prepare(“调用更新投标(?,,…)”;
$stmt->execute(数组($parameter1,$parameter2,…);
}

继续检查代码,以帮助防止不必要的数据库调用,存储过程将有助于确保没有并发问题。

hmmm很好,实际上我是mysql的新手,不知道它有过程功能,我一定会研究它。感谢5.0.0中提供了对存储过程的“基本支持”
If($postedBid < $currentBid + $increment){
   Return;(without processing bid!)
} else {
   $stmt = $db->prepare("CALL update_bid(?,?, ...)");
   $stmt->execute(array($parameter1, $parameter2, ...));
}