Copyright © Deep Blue Sky Digital Limited 2010
Version 0.1.0
This software is developed by Deep Blue Sky, Web Design experts in Bath & Brisol
MyTransaction is a PHP library which provides software layer transaction emulation for the MyISAM storage engine. For background information please read this article - MyISAM Transactions on my blog.
MyTransaction is distributed under the MIT License which basically means you can do what you like with it so long as you don't remove our copyright notice.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
MyTransaction is a pretty experimental idea and it does not provide the sort of protection provided from a true transactional storage engine like InnoDB.
If you need transaction support in a production environment use InnoDB!
There are four stages to installation:
Last but not least you need to replace your call(s) to mysql_query($query) for one that allows the transaction engine to take over if required.
The transaction engine will only grab INSERT, UPDATE and DELETE statements.
Somewhere in your database library you'll be making a call to mysql_query() with a query string and a resource_id. We expect this code to be:
$result = mysql_query( $queryString, $resourceId );
In the file transaction_switch.php you'll find a few lines of code to help you replace that code with a few lines that make a decision as to whether to just do that or, if you have a transaction running, to hand the query off to the transaction library to deal with on your behalf.
// assuming that somewhere you do: $db = new db(); $db -> connect(); // start your transaction: $transaction_id = $db -> start_transaction(); // now assuming you originall did this: $db -> insert_statement('INSERT INTO foo (a,b) VALUES (1,2),(3,4)'); $db -> update_statement('UPDATE bar SET flibble = 101 WHERE wibble = 99'); // now finally you can make a decision about whether you really want to do that.. if ( $i_am_happy ) { $db -> commit_transaction ( $transaction_id ); } else { $db -> rollback_transcation ( $transcation_id ); }
NB. If you don't explicitly commit your transactions the library will make every attempt to roll them back when the request finishes!