dtrt2368 2013-05-02 18:24
浏览 18

如何在更新数据库时停止重复输入和丢失序列

i am taking max invoice no. from a table and incrementing 1 in it and updating the same table with the incremented value, the problem is that multiple users are performing this operation, so some time its misses the sequence and some time is generating same sequence for different jobs. I can't make invoice no field unique as for other jobs its is 0. the code is like.

$res=mysql_query("select max(invoice_no) from complaints_master");
$result=mysql_fetch_array($res);
$code_id=$result[0]+1;
// update invoice details in complaint master
$usr="update complaints_master set invoice_no='$code_id', invoice_flag='1', invoice_date='$today', invoice_total_amt='$_POST[final_total]' where job_no='$_REQUEST[job_no]'";
  • 写回答

1条回答 默认 最新

  • dongmei9961 2013-05-02 18:41
    关注

    You need to set the transaction level to SERIALIZABLE to ensure each MAX(invoice_no)+1 returns a unique value to the client. Not sure how you do that while using PHP, but here is the MySQL doc: MySQL SET TRANSACTION Syntax.

    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧