If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Multiple updates

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-04-11, 17:08
oldnickj oldnickj is offline
Registered User
 
Join Date: Jan 2009
Posts: 103
Multiple updates

I also posted this at sitepoint, not sure where to look for help!
Apologies for my lack of scripting skills. I’m trying to adapt a PayPal IPN script to update several tables in one go.

This script works fine: $strQuery2 =

"UPDATE user_usr
SET amt_paid_usr='".$mc_gross."'
, paypal_usr='".$txn_id."'
, paymentdate_usr='".$fecha."'
WHERE invoice_usr='".$custom."'";
"


$result = mysql_query($strQuery2) or die("Subscription - paypal_subscription_info, Query failed:<br>" . mysql_error() . "<br>" . mysql_errno());

When adding a second query it fails:

"UPDATE user_usr
SET amt_paid_usr='".$mc_gross."'
, paypal_usr='".$txn_id."'
, paymentdate_usr='".$fecha."'
WHERE invoice_usr='".$custom."'";

"UPDATE transactions
SET amt_paid_trn='".$mc_gross."'
, paypal_usr='".$txn_id."'
, paymentdate_trn='".$fecha."'
WHERE '".$item_name."'
LIKE '%G%' AND gifter_trn='".$custom."'";



$result = mysql_query($strQuery2) or die("Subscription - paypal_subscription_info, Query failed:<br>" . mysql_error() . "<br>" . mysql_errno());

I also tried to enclose in quotes rather than two separate sets:

$strQuery2 = "UPDATE user_usr
SET amt_paid_usr='".$mc_gross."'
, paypal_usr='".$txn_id."'
, paymentdate_usr='".$fecha."'
WHERE invoice_usr='".$custom."';

UPDATE transactions
SET amt_paid_trn='".$mc_gross."'
, paypal_usr='".$txn_id."'
, paymentdate_trn='".$fecha."'
WHERE '".$item_name."' LIKE '%G%'
AND gifter_trn='".$custom."'";


$result = mysql_query($strQuery2) or die("Subscription - paypal_subscription_info, Query failed:<br>" . mysql_error() . "<br>" . mysql_errno());


Thanks
Nick
Reply With Quote
  #2 (permalink)  
Old 01-04-11, 18:21
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,535
i think this is a php problem, the php interface can execute only one SQL statement at a time

i think

in any case you should really be looking at implementing a database transaction for this process
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 01-04-11, 18:38
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 623
As has been mentioned in the previous post this should be split into two separate UPDATE statements and use a transaction to keep consistency. So this would be done with:

Code:
mysql_query("BEGIN");
try {
  mysql_query("UPDATE ....");
  mysql_query("UPDATE ...");
  mysql_query("COMMIT");
} catch (Exception $e) {
  mysql_query("ROLLBACK");
}
The try/catch has been added to make sure that if the processing fails that the transaction gets rolled back to the state it was prior to starting the transaction.
__________________
Ronan Cashell
Senior Oracle/MySQL DBA
http://www.it-iss.com
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On