php - mysqli equivalent to mysql_query("BEGIN") -


i'm in process of upgrading our code base php5.4 php7. in our tests wrap entire test in transaction command

mysql_query("begin");

then bunch of stuff

mysql_query("rollback");

then between 2 commands treated transaction , rolled @ end of test. have not been able achieve functionality in php7 mysqli. tried using mysqli_autocommit function did not allow different queries within test have access created data earlier in test. if each insert in own transaction.

update:

the issue every time create new adapter table, seems creating new connection db. php5 , command above 'mysql_query("begin")' every connection contained in transaction , statements rolled back. have not found way php7. if use

$mysqli->begin_transaction(); 

then single connection part of transaction. in order achieve desired functionality, have implicitly force every adapter use existing connection rather creating own. imagine there way php7 automatically you? since way figure out how set global , if exists use connection rather create new one. question still stands, there way force connections opened contained in transaction can rolled back, , further question here best practice re-using connections i'm sure setting global wrong way it.

i using mysql 5.5.52. php 7.0.10

i imagine there way php7 automatically you?

no.

the way figure out how set global

not quite.

you use oop instead , provide single sql adapter instance classes may need it. however, if code procedural, may keep either global variable or singleton helper class.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -