We use use PHP to create a MySQL Transaction. Ill explain what a MySQL transaction is and how to use it with the MySQLi driver. Once you do understand this, …
Original source
We use use PHP to create a MySQL Transaction. Ill explain what a MySQL transaction is and how to use it with the MySQLi driver. Once you do understand this, …
Original source
28 responses to “PHP MySQL Transaction Tutorial”
perfect…
Thanks man, that helped me so much!
Tnq
I don't get what is the purpose of Rollback vs. Commit when there are no errors. Cause, when Autocommit is off, it won't insert data in to database, unless you Commit.
Muy Bien.
so helpful, THUMBS UP!!!!
Really cool tut! Thanks alot!!
Very good tutorial. However for PDO its a little different. You need to disable commit by PDO:beginTransaction PDO does not have auto commit
great man. thanks
Suppose 2 concurrent transactions were trying to perform the SAME operations, how would the database handle that? For instance in a banking scenario i.e. money transfer. Wouldnt consistency get screwed up?
@aalamnaryab lol
@AmrGamal878 have you tried magento ? or just want to do it yourself ?
Once I implemented this and my current boss was angry; he said mySQL transactions weren't fully suported (in 2010/July, don't know what version was using, but I'm sure was 5+)
What do you think ? is this reliable ?
We want a tutorials series for making PHP shopping card in OOP fashion , people who agree with me plz like this comment to make it top comment , so the author can see
this helped me a lot, thanks
@stokescomp NICE!!!
There is another way you could do transactions. One thing you can do is make savepoint commands so you can roll back to a certain point instead of to the last commit so you save your progress when its at a safe point. You can build it into a mysqli helper class like this.
function transaction_savepoint($name)
{
$this->query("SAVEPOINT $name");
}
function transaction_rollback($name = null)
{
$this->query("ROLLBACK" . ($name != null ? " TO SAVEPOINT $name" : ""));
}
Great video!! More people need to use these.
Here is the manual on how to do rollbacks: php.net/manual/en/mysqli.rollback.php
The best thing to do is try it. Practice is a good thing with this stuff.
It's effin funny that you managed to make me reallise what is this transaction all about in half a minute while a College teacher in 3 hours didn't…
@MunzirSuliman Edit your php.ini file and uncomment mysqli.dll or mysqli.so
@sachinprasad1234 It's built into PHP. If you compiled PHP by source, you will need to tell the config script that you want to enable MySQLi at compile time. But yeah, it is compiled directly into PHP.
I'm not sure what version of PHP this affects, but in some version MySQL or even MySQLi are not shipped as standard anymore. Meaning, you have to install them yourself. This might just be for us Linux guys. Not entirely sure.
Wow the sound is so crystal clear. Thanks very much Jesse! ๐
Thanks nice tutorial …
@sultan880 Thanks for watchin ๐
@combantsystems YW!
@MunzirSuliman Its due to the Yeti Blue Mic ๐
@frosty1433 Because if you run a query again it might be internally stored. So you could have a bunch of rows pending in the queue- and if you run again and it succeeds, you'll get double the stuff.
thx ๐