Hello friends,
你好朋友,
I have a mysql db and a php page . When I or someone call my php page it is updating my table smoothly.
我有一个mysql数据库和一个php页面。当我或某人调用我的php页面时,它会顺利更新我的表格。
But when it is called by more then one user at same moment, it is not updating the table correctly . It is updating only one user's process . I m using standart mysql connection. I have tried ADO DB connection but problem was not solved . What is the problem ?
但是当它被同一时刻的多个用户调用时,它不会正确地更新表。它只更新一个用户的进程。我使用标准的mysql连接。我尝试过ADO DB连接,但问题没有解决。问题是什么 ?
This is my php page;
这是我的php页面;
<?php
$host ="******.com";
$uname = "*****";
$pwd = "*******";
$db = "*****_db";
$con = mysql_connect($host,$uname,$pwd) or die("connection failed");
mysql_select_db($db,$con) or die("db selection failed");
$id = $_REQUEST['id'];
$int_id = intval($id);
$value = 0;
if (isset($_REQUEST['vote1']))
{
$vote1 = $_REQUEST['vote1'];
$value = 1;
$vote = intval($vote1);
}
if (isset($_REQUEST['vote2']))
{
$vote2 = $_REQUEST['vote2'];
$vote = intval($vote2);
$value = 2;
}
//Get Detail
mysql_query("SET NAMES 'utf8'");
mysql_query ("SET CHARACTER SET utf8");
mysql_query ("SET COLLATION_CONNECTION = 'utf8_general_ci'");
// get all products from products table
$res_detail = mysql_query("SELECT *FROM v_list WHERE id='$int_id'") or die(mysql_error());
if (mysql_num_rows($res_detail) > 0) {
while ($row = mysql_fetch_assoc($res_detail)) {
if($value ==1 )
{
$fark = $vote1 - $row["vs1_vote"];
if($fark == 1)
{
$sum_vote = $vote1 + $row["vs2_vote"] ;
$v1_percent = round( ($vote1 *100 / $sum_vote), 2);
$v2_percent = 100 - $v1_percent;
}
else
{
echo "An error occoured";
}
}//value1
if($value ==2 )
{
$fark = $vote2 - $row["vs2_vote"];
if($fark == 1)
{
$sum_vote = $row["vs1_vote"] + $vote2 ;
$v2_percent = round(($vote2 *100 / $sum_vote),2);
$v1_percent = 100 - $v2_percent;
}
else
{
echo "An error occoured";
}
}//value2
}//while
}//if
$date = date('Y-m-d H:i:s');
$flag['code']=0;
if($value ==1 )
{
if($r=mysql_query("UPDATE v_list SET vs1_vote='$vote',vs1_percent='$v1_percent',vs2_percent='$v2_percent',allvotes='$sum_vote' WHERE id='$int_id'",$con))
{
$flag['code']=1;
echo"hi";
}
}
if($value ==2 )
{
if($r=mysql_query("UPDATE v_list SET vs2_vote='$vote',vs1_percent='$v1_percent',vs2_percent='$v2_percent',allvotes='$sum_vote' WHERE id='$int_id'",$con))
{
$flag['code']=1;
echo"hi";
}
}
print(json_encode($flag));
mysql_close($con);
?>
1 个解决方案
#1
0
what is your table type (Innodb / MyISAM). In Innodb there is row level locking of records.so one user at a time but not as with MyISAM, in it table level locking. so try to make your table Innodb type.
你的桌子类型是什么(Innodb / MyISAM)。在Innodb中有记录的行级锁定。一次一个用户,但不像MyISAM那样,在表级锁定中。所以尽量让你的表Innodb类型。
#1
0
what is your table type (Innodb / MyISAM). In Innodb there is row level locking of records.so one user at a time but not as with MyISAM, in it table level locking. so try to make your table Innodb type.
你的桌子类型是什么(Innodb / MyISAM)。在Innodb中有记录的行级锁定。一次一个用户,但不像MyISAM那样,在表级锁定中。所以尽量让你的表Innodb类型。