[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2003-12-12
5
Medium Priority
?
243 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 500 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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…
Suggested Courses

656 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