A tricky and interesting mysql-php problem................
| From: | vishal at eluminoustechnologies dot com | Date: | Sat, 17 May 2003 17:41:00 +0000 |
| Subject: | A tricky and interesting mysql-php problem................ | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-148030@lists.php.net to get a copy of this message | ||
A tricky and interesting mysql-php problem................
I am executing a script in php.
This executes a 3 mysql queries
e.g.
$query11="select * from ".$prefix."account where username='$Cusername' and
current=1";
$result11=mysql_query($query11);
$total11=mysql_num_rows($result11);
if($total11)
{
$row11=mysql_fetch_object($result11);
$bal=$row11->balance;
}
else
$bal=0;
$queryc="update ".$prefix."account set currentrec=0 where
username='$user'";
$resultc=mysql_query($queryc);
$queryacc="insert into
".$prefix."account(username,deposited,balance)values('$user','$pay','$newbal
')";
$resultacc=mysql_query($queryacc);
This updates account of a user
If user purchase 10 items at a time then this 3 mysql queries executes 10
times in a loop as per the requirement.
Now when there are 10-20 such users online at a time and if they purchase
10-10 items
this mysql queries executes 100-200 times. Untill here its ok.
But here after the problem starts. Mysql should not allow the second user
for loop to execute until the first user for loop is completed. It randomly
takes the user and starts executing the mysql query in for loop before
satisfying the first user.
for($i=1,$i<=10;$i++)
{
$query11="select * from ".$prefix."account where username='$user' and
current=1";
$result11=mysql_query($query11);
$total11=mysql_num_rows($result11);
if($total11)
{
$row11=mysql_fetch_object($result11);
$bal=$row11->balance;
}
else
$bal=0;
$queryc="update ".$prefix."account set currentrec=0 where
username='$user'";
$resultc=mysql_query($queryc);
$queryacc="insert into
".$prefix."account(username,deposited,balance)values('$user','$pay','$newbal
')";
$resultacc=mysql_query($queryacc);
}
It executes $query11 for first user and then again $query11 for second user
then
$queryc for first user and so on ............
anything randomly happens here.
We just cant predict what will happen.
This leads to all wrong accounts .And its a big problem.
I want that it should first complete request for first user and then for
second and so on.....
If first users request is not completed it should hold second user for that
time and so on...
Is anybody having same problem or any solution?
Thank you,
Tina...