Note that there are some explanatory texts on larger screens.

plurals
  1. POphp mysql pdo auction bidding
    primarykey
    data
    text
    <p>I am developing an auction system with a limit or max bid scenario using php mySQL(MyISAM) and PDO, using two tables </p> <p><strong>auction</strong></p> <pre><code> Id | title | seller | currentbid | limit(max bid) | dated | bidder </code></pre> <p><strong>bids</strong></p> <pre><code> Id | auctionid | bid | bidder | dated </code></pre> <p>After user placed a bid the following happens (I am using PDO prepared statements)</p> <pre><code> $record = fetch (‘Select * from auction where id = :id’, array(‘id’ =&gt; $id)) $increment = 1; $postedBid = $_REQUEST[‘postedBid’]; $currentBid = $record[‘currentbid’]; $limitBid = $record[‘limit’]; If($postedBid &lt; $currentBid + $increment){ Return;(without processing bid!) }else{ If($limitBid !&gt; $postedBid){ Insert into bids (auctionid, bid, bidder, dated(timestamp)) values ($auctioned, $postedBid, ……); Update auction set currentbid = $postedBid, limit = $postedBid …. }else{ Insert into bids (auctionid, bid, bidder, dated(timestamp)) values ($auctioned, $postedBid, ……); Insert into bids (auctionid, bid, bidder, dated(timestamp)) values ($auctioned, $postedBid + $increment, ……); Update auction set currentbid = $postedBid + increment, limit = $limitBid …. } } </code></pre> <p>i want to know two things</p> <p>1- if this approach is ok and how can I improve this</p> <p>2- How can I avoid concurrent bids. I don’t know how to apply locks using PDO. Appreciate any example queries using locks or any other approach to deal with this problem</p> <p>Thanks </p> <p>(Apologies for using mixed type of code)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload