php - 更新停止在 768 条记录

标签 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);
    }
}
?>

最佳答案

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

关于php - 更新停止在 768 条记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24694401/

相关文章:

MySQL:使用 LONGTEXT 而不是 MEDIUMTEXT 是否缺乏性能?

mysql - Xampp Mysql 不工作

php - mysql搜索短语使用不区分大小写的匹配

mysql - Spring JPA OneToMany 重复条目 MySQLConstraint 违规错误

php - Laravel - 在 Eloquent 模型中返回自定义额外数据

php - 声明 "PHP doesn' t scale up (well)”背后的基本原理是什么?

php - 所有项目中只有一个 mysql 连接

php - 如何一次回显 php 数组的所有元素?

php - 检查是否存在任何错误消息并在 laravel 中显示所有错误消息

php - 非常简单的jquery AJAX post问题