Solved

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

Posted on 2003-12-12
5
240 Views
Last Modified: 2006-11-17
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
Comment
Question by:davepusey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 6

Accepted Solution

by:
DoppyNL earned 125 total points
ID: 9927252
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
 
LVL 2

Author Comment

by:davepusey
ID: 9927287
>> 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
 
LVL 6

Expert Comment

by:DoppyNL
ID: 9927299
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
 
LVL 6

Expert Comment

by:DoppyNL
ID: 9927306
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
 
LVL 2

Author Comment

by:davepusey
ID: 9927400
Ok, I'll stick with what I put then!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question