简体   繁体   中英

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.

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.

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.

Note 2: We are using separate connection string for read and write connections using 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. As far as my knowledge is concerned I found this solution, experts please review or confirm my answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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