A
A
Alexey2016-04-08 16:14:38
MySQL
Alexey, 2016-04-08 16:14:38

Can a connection break occur when several items are written to the database?

I am working on creating an online store. I suppose that my question concerns the features of the MySQL server.
Essence:
At the time of order formation, 2 manipulations occur:
1. A new order is created in the `orders` table
2. According to the `id` of the newly created order, we write the parameters of the goods of this order into the `order_details` table (product id, quantity, sale price).
Suppose there are 30-40 items in an order. Can it happen that in the process of filling the `order_details` table, a connection break occurs (or some other problem), as a result of which the order composition is not completely saved?
If yes, how can this be avoided? And is it worth it to provide for the "processing" of such situations?
The table engine used is MyISAM.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Maxim Fedorov, 2016-04-08
@Alexey-V-Ivanov

Anything could happen. As a rule, such situations are solved using transactions. But to use them, you should switch from MyISAM to InnoDB . You
can read more about them here. Specifically, in your case, you should go

C
Cat Anton, 2016-04-08
@27cm

Can a connection break occur when several items are written to the database?

Maybe.
There is no way to avoid it 100%. The cleaning lady can always accidentally pull the server out of the socket.
Use the transaction mechanism. This way you guarantee that either all requests will be fulfilled, or none. You will either have to abandon MyISAM, or implement the transaction mechanism yourself at the application code level (most likely a bad idea), or accept and leave everything as it is.

M
Muhammad, 2016-04-08
@muhammad_97

Use transactions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question