LLLLLLL Posted August 26, 2010 Share Posted August 26, 2010 On MySQL 5.1.47, PHP 5.2.14 I have looked at every PHP and MySql website I can find, and I'm sure my syntax must be incorrect, but I don't know how, why, or where. All I want to do is put this information in a transaction. Many queries are being run, and I don't want one failure to screw up everything else. You'll notice that there aren't many queries here... most of them are in the classes themselves. Maybe that matters; not sure. Anyway, for testing purposes I'm simply calling ROLLBACK at the end of all this. Alas, nothing is rolled back, and all the queries succeeded in adding information to the DB. Because of this, I'm convinced my transaction syntax is wrong. I've tried many ways, and this just happens to be the current syntax. Please help! mysql_query( 'SET AUTOCOMMIT=0' ); mysql_query( 'BEGIN' ); $cust->findIdOrAdd( $adrs ); // add the order to the db $order->add(); // before adding products, we need to map the skus to ids $skumap = array(); $sql = 'select sku, id from products'; $result = mysql_query( $sql ); while ( $data = mysql_fetch_assoc( $result ) ) { $skumap[ $data[ 'sku' ] ] = $data[ 'id' ]; } // loop through all the items. set the orderid and custid, // and then call the add function, passing in the skumap foreach ( $order->products as $product ) { $product->add( $skumap ); } mysql_query( 'ROLLBACK' ); mysql_query( 'SET AUTOCOMMIT=1' ); Quote Link to comment https://forums.phpfreaks.com/topic/211815-mysql-transaction-not-working/ Share on other sites More sharing options...
Mchl Posted August 26, 2010 Share Posted August 26, 2010 Are the tables InnoDB? Quote Link to comment https://forums.phpfreaks.com/topic/211815-mysql-transaction-not-working/#findComment-1104093 Share on other sites More sharing options...
LLLLLLL Posted August 26, 2010 Author Share Posted August 26, 2010 I don't know. Can you tell me how to find out that info? (FYI: my web host says transactions are supported.) Quote Link to comment https://forums.phpfreaks.com/topic/211815-mysql-transaction-not-working/#findComment-1104096 Share on other sites More sharing options...
Mchl Posted August 26, 2010 Share Posted August 26, 2010 Run SHOW CREATE TABLE tableName and see what's next to ENGINE= Quote Link to comment https://forums.phpfreaks.com/topic/211815-mysql-transaction-not-working/#findComment-1104099 Share on other sites More sharing options...
LLLLLLL Posted August 26, 2010 Author Share Posted August 26, 2010 Ah. ENGINE=MyISAM Does MyISAM support transactions? Quote Link to comment https://forums.phpfreaks.com/topic/211815-mysql-transaction-not-working/#findComment-1104102 Share on other sites More sharing options...
Mchl Posted August 26, 2010 Share Posted August 26, 2010 It doesn't. If you want transactions, you need to switch to InnoDB (or other engine that supports them, if you have them available) InnoDB on the other hand does not support full-text searches, but is otherwise much more robust than MyISAM. Quote Link to comment https://forums.phpfreaks.com/topic/211815-mysql-transaction-not-working/#findComment-1104105 Share on other sites More sharing options...
LLLLLLL Posted August 26, 2010 Author Share Posted August 26, 2010 Well that sucks. But I do thank you for this information. Quote Link to comment https://forums.phpfreaks.com/topic/211815-mysql-transaction-not-working/#findComment-1104107 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.