简体   繁体   English

有时会丢失InnoDB更新和插入数据(PHP和MySQL)

[英]InnoDB update and insert data missing sometimes (PHP and MySQL)

Our need is to update some columns in both master and sub tables (table_1 and table_2), both tables are in InnoDB engine, actually it updates correctly, but sometimes in any one table the update action is not happening. 我们需要更新主表和子表(table_1和table_2)中的一些列,两个表都在InnoDB引擎中,实际上它正确更新,但有时在任何一个表中都没有发生更新操作。

We had checked the query execute status and tried checking MySQL load at that time we couldn't able to find any solution, please look into it and try to give a better solution to us, kindly update us if you want any further information from us. 我们已经检查了查询执行状态并尝试检查MySQL加载,那时我们无法找到任何解决方案,请查看它并尝试为我们提供更好的解决方案,如果您需要我们的任何进一步信息,请更新我们。

Note 1 : As far as we studied InnoDB has row level locking so it wont affect other rows insert or update functions, can you suggest us at what situation InnoDB fails to respond or any other suggestions in coding wise or whatever may be, waiting for your answer. 注1:据我们研究过InnoDB有行级锁定所以它不会影响其他行插入或更新函数,你能否告诉我们InnoDB在什么情况下无法响应或者编码明智或其他任何可能的建议,等待你的回答。

Note 2: We are using separate connection string for read and write connections using PDO. 注2:我们使用单独的连接字符串来使用PDO进行读写连接。

I have written my code below for your reference. 我在下面编写了我的代码供您参考。

$Update_CCPI_qy = "UPDATE `table_1` SET `status` = :status, `idActivateTime` = :currentTime WHERE `student_id` = :candidateID";

$Update_CCPI_exec = $pdo_connection_write->prepare($Update_CCPI_qy);
$Update_CCPI_status = $Update_CCPI_exec->execute(array( ':candidateID' => $candidateID, ':status' => 1, ':currentTime' => time()));

$Update_candidateIDNo_qy = "UPDATE `table_2` SET `status` = :status, `idActivateTime` = :currentTime WHERE `candidateid` = :candidateID";
$Update_candidateIDNo_exec = $pdo_connection_write->prepare($Update_candidateIDNo_qy);
$Update_candidateIDNo_status = $Update_candidateIDNo_exec->execute(array( ':candidateID' => $candidateID, ':status' => 1, ':currentTime' => time()));

I myself declare that after a long discussion, research and analysis somewhere I found that innodb is not consistent at some stage which comes just before dead lock of that table so innodb can manage not to get into dead lock but at certain level it becomes inconsistent at times which means it doesn't shows the results correctly and it may not insert or update at that times. 我自己声明,经过长时间的讨论,研究和分析,我发现innodb在某个阶段不一致,这个阶段刚好在该表的死锁之前,因此innodb可以设法不进入死锁,但在某种程度上它变得不一致时间,这意味着它没有正确显示结果,并且可能不会在那时插入或更新。 As far as my knowledge is concerned I found this solution, experts please review or confirm my answer. 就我的知识而言,我找到了这个解决方案,专家请回顾或确认我的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM