更新停止在768记录

时间:2014-07-11 09:26:26

标签: php mysql

我运行的这个脚本是更新表,我遇到的问题是,在运行更新的过程中,它只是停止更新第768行的表。

为什么会发生这种情况?

脚本1称为doAllocate.php,如下所示:

<?php
$status=trim($_GET['status']);
$region=$_GET['regg'];
include_once ('connstring.php');

$dir=1;
$query ;
$flag="unattended";
$cids=array();
$acc=array();
$c=0;
$a=0;
$var="";
$q="";
$p;     

$dbhandle = mysql_connect($hostname, $username, $password)
or die("<script> alert('Unable to connect to MySQL'); </script>");

$selected = mysql_select_db("edgars",$dbhandle)
or die("<script> alert('Could not select database'); </script>");

$query1="SELECT * 
           FROM collectors 
          WHERE status='$status' AND 
                region='$region' ";
//$query1="SELECT * FROM collectors where status='1' and region='1' ";
$res1=mysql_query($query1);
$i=0;
while($r=mysql_fetch_array($res1))
{
    $cids[$i]=$r['cid'];
    $i++;
}

$query="SELECT * 
          FROM customers  
         WHERE status='$status' AND 
               flag='$flag' AND 
               region='$region' AND 
               cid='' 
      ORDER BY total_due DESC";
//$query="SELECT * FROM customers  where status='1' and flag='$flag' and region='1' ORDER BY total_due DESC";

$res=mysql_query($query);
$num=mysql_num_rows($res);
$j=0;

while($row = mysql_fetch_array($res))
{
    $acc[$j]=$row['account'];
    $j++;
}

for($c=0,$a=0 ; $c<count($cids),$a<count($acc);$c++,$a++)   
{
    $q= mysql_query("UPDATE customers 
                        SET cid='$cids[$c]' 
                      WHERE account='$acc[$a]' AND 
                            cid=''");
    $rcount = mysql_affected_rows();
    if($rcount > 0)
    {
        header("Location: doAllocateRev.php?status=".$status."&regg=".$region);
    }
}
?>

脚本2称为doAllocateRev.php,如下所示:

<?php
$status=trim($_GET['status']);
$region=$_GET['regg'];
include_once ('connstring.php');

$dir=1;
$query ;
$flag="unattended";
$cids=array();
$acc=array();
$c=0;
$a=0;
$var="";
$q="";
$p;     

$dbhandle = mysql_connect($hostname, $username, $password)
or die("<script> alert('Unable to connect to MySQL'); </script>");

$selected = mysql_select_db("edgars",$dbhandle)
or die("<script> alert('Could not select database'); </script>");

$query1="SELECT * 
           FROM collectors 
          WHERE status='$status' AND 
                region='$region' ";
//$query1="SELECT * FROM collectors  where status='1' and region='1' ";
$res1=mysql_query($query1);
$i=0;
while($r=mysql_fetch_array($res1))
{
    $cids[$i]=$r['cid'];
    $i++;
}

$query="SELECT * 
          FROM customers  
         WHERE status='$status' AND 
               flag='$flag' AND 
               region='$region' AND 
               cid='' 
      ORDER BY total_due DESC";
//$query="SELECT * FROM customers  where status='1' and flag='$flag' and region='1' ORDER BY total_due DESC";

$res=mysql_query($query);
$num=mysql_num_rows($res);
$j=0;

while($row = mysql_fetch_array($res))
{
    $acc[$j]=$row['account'];
    $j++;
}

for( $c=count($cids)-1; $c>=0,$a<count($acc) ; $c--,$a++)   
{
    $p= mysql_query("UPDATE customers 
                        SET cid='$cids[$c]'
                      WHERE account='$acc[$a]' AND
                            cid=''");
    $rcount = mysql_affected_rows();
    if($rcount > 0) 
    {
        header("Location: doAllocate.php?status=".$status."&regg=".$region);
    }
}
?>

2 个答案:

答案 0 :(得分:0)

我无法确切地告诉您要将哪些内容放入数据库,但我知道当您尝试将长度超过767的密钥写入innoDb表时,mysql会产生错误。请参阅http://dev.mysql.com/doc/refman/5.5/en/innodb-restrictions.html(“默认情况下,单列索引的索引键最多可达767个字节”)。你达到768的限制这一事实让我怀疑这是相关的。如果这是巧合,那就是一个有趣的。

答案 1 :(得分:0)

这里有两点可能有帮助。

$p= mysql_query("UPDATE customers 
                    SET cid='$cids[$c]'
                  WHERE account='$acc[$a]' AND
                        cid=''");

避免这种情况。正确连接变量:

$p= mysql_query("UPDATE customers 
                    SET cid='" . $cids[$c] . "'
                  WHERE account='" . $acc[$a] . "' AND
                        cid=''");

我最近有一个类似的问题:Data is getting lost during $.post

可能是由于max_input_vars变量。

分享ini_get('max_input_vars');的输出并考虑提高它。