search

Home  >  Q&A  >  body text

mysql - How does PHP handle the Duplicate entry '' for key 'num' (23000) problem caused by unique indexes?

I have a project that requires interface transmission, which is similar to recharge. I need to receive the order number and put it into the warehouse. There is a variable called a timestamp. Based on this timestamp, I can retrieve the recharge information after this timestamp.
But there is a problem. Yes, in order to prevent missing orders, when I search every 5 minutes, I will increase the timestamp by 28000 instead of 300000. This will cause the order number to be repeated and lead to failure. Thinkphp solves this problem, but it is embarrassing. I use is not a TP framework. Is there any other way to solve this problem?

学习ing学习ing2700 days ago1061

reply all(3)I'll reply

  • 漂亮男人

    漂亮男人2017-07-04 13:45:35

    The key is repeated, which means the empty string inside. What does this have to do with what you said?
    It means that the num column has multiple blank strings'' to be inserted into the database.

    I didn’t understand your explanation at all.

    reply
    0
  • 高洛峰

    高洛峰2017-07-04 13:45:35

    If you use a unique index, the default value can be set to NULL. NULL values ​​will not conflict, but 0 or empty strings '' will conflict.

    reply
    0
  • 黄舟

    黄舟2017-07-04 13:45:35

    This error is caused by the database

    reply
    0
  • Cancelreply