dpb_4431 2018-04-28 08:34
浏览 98

如何检查mysql更新查询是否成功?

function insertNewBidPrice($code, $newBidPrice)
{
  global $conn;
  $sql = "update auctionitem set highestbid=$newBidPrice where code=$code";
  //echo $sql;
  if($conn->query($sql))
  {
    return 1;
  }
  else
  {
    require 0;
  }
}

I have this php fuction that results 0 all time although update query successfully update the table.

I use PDO.

$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  • 写回答

2条回答 默认 最新

  • doujiao9866 2018-04-28 08:45
    关注

    Create a statement object first, using prepare.

    $stmt = $conn->prepare($sql);
    $worked = $stmt->execute();
    if ($worked == TRUE) {
        //I did stuff
    } else {
        // nope
    }
    
    评论

报告相同问题?