PHP复制代码 class Consume_model extends CI_Model
{
public function __construct ()
{
parent ::__construct ();
}
/**
* 扣费操作
* @param array $orderinfo
* @return number
*/
public function addconsume (array $orderinfo)
{
$this->db->trans_start();
$sql="select amount from userinfo where uid=".$orderinfo['uid']." for update";
$val = $this->db->query($sql)->row()->amount;
if(!$val || ($val<$amount))
{
$this->db->trans_complete();
return -1; //余额不足
}
$this->db->query("update userinfo set amount=amount-".$orderinfo['amount']." where uid=".$orderinfo['uid']);
$this->db->query("......................");
$this->db->trans_complete();
return $this->db->trans_status();
}
}
复制代码
每次执行这个地方就会出错:
Lock wait timeout exceeded; try restarting transaction update userinfo set amount=amount-10.00 where uid=927 为什么会产生这样的错误?难道不是用$this->db->trans_start()调用?
|