• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 244
  • Last Modified:

Is is possible to execute both queries at the same time?

At present I have this snippet code that does a little bit of cleanup on my database...

    /* Performing SQL query */
  $query_rsJobsDoPost = "UPDATE jobs SET currentbatch='0',done='y' WHERE currentbatch='2'";
  $rsJobsDoPost = mysql_query($query_rsJobsDoPost, $dbEECleanup) or die(mysql_error() . "<BR>SQL=" . $query_rsJobsDoPost);
  $row_rsJobsDoPost = mysql_fetch_assoc($rsJobsDoPost);

    /* Performing SQL query */
  $query_rsJobsDoPost = "UPDATE jobs SET currentbatch='0',done='n' WHERE currentbatch='1'";
  $rsJobsDoPost = mysql_query($query_rsJobsDoPost, $dbEECleanup) or die(mysql_error() . "<BR>SQL=" . $query_rsJobsDoPost);
  $row_rsJobsDoPost = mysql_fetch_assoc($rsJobsDoPost);


Is is possible to execute both queries in one go. In phpMyAdmin I can simply put...

UPDATE jobs SET currentbatch='0',done='y' WHERE currentbatch='2';
UPDATE jobs SET currentbatch='0',done='n' WHERE currentbatch='1';

as my SQL statement and it works ok. How can I do this in my PHP script?
0
davepusey
Asked:
davepusey
  • 3
  • 2
1 Solution
 
DoppyNLCommented:
you can't do that in PHP.
You can do as many mysql_query() as you want however, so you can simply run the second right after the first.
That is also what PHPmyadmin does, it splits it up, then executes it one at a time.

this line
$row_rsJobsDoPost = mysql_fetch_assoc($rsJobsDoPost);
won't work, as it is an update query, those query's don't return results!
0
 
davepuseyAuthor Commented:
>> this line
>> $row_rsJobsDoPost = mysql_fetch_assoc($rsJobsDoPost);
>> won't work

Well it dont cause any errors

>> You can do as many mysql_query() as you want however, so you can simply run the second right after the first.
>> That is also what PHPmyadmin does, it splits it up, then executes it one at a time.

So basically I need to do this...

/* Performing SQL query */
$query_rsJobsDoPost = "UPDATE jobs SET currentbatch='0',done='y' WHERE currentbatch='2'";
$rsJobsDoPost = mysql_query($query_rsJobsDoPost, $dbEECleanup) or die(mysql_error() . "<BR>SQL=" . $query_rsJobsDoPost);
$query_rsJobsDoPost = "UPDATE jobs SET currentbatch='0',done='n' WHERE currentbatch='1'";
$rsJobsDoPost = mysql_query($query_rsJobsDoPost, $dbEECleanup) or die(mysql_error() . "<BR>SQL=" . $query_rsJobsDoPost);
0
 
DoppyNLCommented:
yep

you can reduce it to this though:

$rsJobsDoPost1 = mysql_query("UPDATE jobs SET currentbatch='0',done='y' WHERE currentbatch='2'", $dbEECleanup) or die(mysql_error() . "<BR>SQL=" . $query_rsJobsDoPost);
$rsJobsDoPost2 = mysql_query("UPDATE jobs SET currentbatch='0',done='n' WHERE currentbatch='1'", $dbEECleanup) or die(mysql_error() . "<BR>SQL=" . $query_rsJobsDoPost);

and if you don't need the result of the query (you are catcing the errors) you can even leave out the assignment of the result to the variable:
mysql_query("UPDATE jobs SET currentbatch='0',done='y' WHERE currentbatch='2'", $dbEECleanup) or die(mysql_error() . "<BR>SQL=" . $query_rsJobsDoPost);
mysql_query("UPDATE jobs SET currentbatch='0',done='n' WHERE currentbatch='1'", $dbEECleanup) or die(mysql_error() . "<BR>SQL=" . $query_rsJobsDoPost);
0
 
DoppyNLCommented:
woops, made a little mistake.
There is still a reference to the failing query-variable (wich I placed directly in the mysql_query variable).
You probably want to change that as well when you do it.

Saying that, the code you posted works just fine :)
0
 
davepuseyAuthor Commented:
Ok, I'll stick with what I put then!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now