Solved

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

Posted on 2003-12-12
5
196 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
  • 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now