MySQL / PHP - possible to run many sql statements in the same execution?
| From: | Matt Babineau | Date: | Thu, 25 Apr 2002 19:45:45 +0000 |
| Subject: | MySQL / PHP - possible to run many sql statements in the same execution? | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-13313@lists.php.net to get a copy of this message | ||
Let me try and explain a little better:
Here is some query code
$query3 = "LOCK TABLES COUNTER_PAGE_VIEWS";
$query = "SELECT Count FROM COUNTER_Page_Views WHERE Counter_ID = '" .
$count_id . "'";
$query1 = "UPDATE COUNTER_Page_Views SET Count = Count + 1 WHERE
Counter_ID = '" . $count_id . "'";
$result3 = mysql_query($query3);
$result1 = mysql_query($query1);
$result = mysql_query($query);
As the page processes, it processes in order, so it owuld go through
those lines of code and do what it needs to do. Currently two users can
cause a threading issue where even if I lock the table, because the call
is not coming from inside MySQL. So the locking only occurs for the
single Query which locks the Table, then the next query execution voids
the write lock on the table.
What I would need to do here is either lump all the queryioes into one
SQL execution or lock the PHP code so it is single threaded like this:
$query3 = "LOCK TABLES COUNTER_PAGE_VIEWS";
$query = "SELECT Count FROM COUNTER_Page_Views WHERE Counter_ID = '" .
$count_id . "'";
$query1 = "UPDATE COUNTER_Page_Views SET Count = Count + 1 WHERE
Counter_ID = '" . $count_id . "'";
<LOCK THE CODE SO ONLY ONE CLIENT CAN RUN AT A TIME>
$result3 = mysql_query($query3);
$result1 = mysql_query($query1);
$result = mysql_query($query);
<RELEASE THE LOCK>
Anyone have any suggestions?
Matt Babineau
Freelance Internet Developer
e: <mailto:mbabineau@illuminatistudios.com>
mbabineau@illuminatistudios.com
p: 603.943.4237
w: <http://www.illuminatistudios.com/> http://www.illuminatistudios.com