See if your try catch operates on the database. Of course it involves updating and inserting multiple tables. In order to ensure the integrity of the data, transaction operations must be enabled
It depends on what is in your catch. If there is only one sentence after try and an exception is thrown, there will be no commit, OK. If doOne is executed and you don’t use the transaction, it will autocommit. Do you want to catch doOne and roll it back separately or what to do? The following are two sentences. If you have 10 sentences, how will you catch them?
Transaction and try catch are two different things. The reason why try catch is used when starting a transaction is because if you use extensions such as pdomysqli, the database error will return an error to php. , let the program executed by PHP terminate, so that the function command of the rollback step cannot be executed (the program is interrupted when the input is executed), and it is much safer to use try catch to perform transaction operations
It is necessary to distinguish clearly try catch is something that belongs to phpjava and other logical operations, while transation is something that belongs to the database. The two can cooperate but cannot replace each other
See if your try catch operates on the database. Of course it involves updating and inserting multiple tables. In order to ensure the integrity of the data, transaction operations must be enabled
It depends on what is in your catch. If there is only one sentence after try and an exception is thrown, there will be no commit, OK.
If doOne is executed and you don’t use the transaction, it will autocommit. Do you want to catch doOne and roll it back separately or what to do?
The following are two sentences. If you have 10 sentences, how will you catch them?
Transaction and
try catch
are two different things. The reason whytry catch
is used when starting a transaction is because if you use extensions such aspdo
mysqli
, the database error will return an error to php. , let the program executed by PHP terminate, so that the function command of therollback
step cannot be executed (the program is interrupted when the input is executed), and it is much safer to usetry catch
to perform transaction operationsIt is necessary to distinguish clearly
try catch
is something that belongs tophp
java
and other logical operations, whiletransation
is something that belongs to the database. The two can cooperate but cannot replace each other