Jump to content

Recommended Posts

:shrug:

 

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' );

 

Link to comment
https://forums.phpfreaks.com/topic/211815-mysql-transaction-not-working/
Share on other sites

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.