duanqiaoren9975 2015-11-25 07:38
浏览 71

PHP mysql数据库未更新为并行

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.

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 ?

This is my php page;

<?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条回答 默认 最新

  • dongyue934001 2015-11-25 08:12
    关注

    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.

    评论

报告相同问题?