Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用PHP复制过多记录?_Php_Mysql_Duplicates - Fatal编程技术网

如何使用PHP复制过多记录?

如何使用PHP复制过多记录?,php,mysql,duplicates,Php,Mysql,Duplicates,我需要读取和处理(例如在IDs的末尾添加一个“2”+一些其他东西…)并使用PHP重新插入至少2000条MySQL记录。 无法使用SQL查询执行此操作。。。 问题是,当我们点击Go按钮时,它处理了近500条记录,但随后我们看到“服务器内部500”错误!但在localhost中,我们没有任何问题 有没有办法利用我们客户网站上这些有限的资源做到这一点 另一个问题:是什么导致了这个问题?什么资源需要更多?内存中央处理器 代码如下: (我们应该阅读一学期的所有课程和所有课程选择,并将它们复制到新学期) 这

我需要读取和处理(例如在IDs的末尾添加一个“2”+一些其他东西…)并使用PHP重新插入至少2000条MySQL记录。 无法使用SQL查询执行此操作。。。 问题是,当我们点击Go按钮时,它处理了近500条记录,但随后我们看到“服务器内部500”错误!但在localhost中,我们没有任何问题

有没有办法利用我们客户网站上这些有限的资源做到这一点

另一个问题:是什么导致了这个问题?什么资源需要更多?内存中央处理器

代码如下: (我们应该阅读一学期的所有课程和所有课程选择,并将它们复制到新学期)


这可能会复制数据库中的所有数据

在ID末尾添加“2”似乎是SQL可以做的事情,而不需要PHP
更新您的表集idfield=concat(idfield,'2')
?@Marc他提到他还想concat其他东西。代码中的某些东西会导致问题。。。。但是,除非您共享您的代码,否则我们无法告诉您什么只是检查服务器上的error.log并告诉我们错误是什么。通过这种方式,我们可以为您提供更多帮助。使用不推荐使用的MySQL扩展,使用
@
抑制潜在的错误消息,并不能真正激发信心
foreach ($courseList as $courseInfo)
    {
        $ccode=$courseInfo['ccode'];
        $lid=$courseInfo['lid'];
        $pid=$courseInfo['pid'];
        $clid=$courseInfo['clid'];
        $cgender=$courseInfo['cgender'];
        $descriptive_score=$courseInfo['descriptive_score'];
        $final_capacity=$courseInfo['final_capacity'];
        $days_times=$courseInfo['days_times'];
        $exam_date=$courseInfo['exam_date'];
        $exam_place=$courseInfo['exam_place'];
        $ccourse_start_date=date("Y-m-d H:i:s");
        $ccomment=$courseInfo['ccomment'];
        $cid=$courseInfo['cid'];
        $majors=$course->GetCourseMajorsList($cid);
        $scList=$course->GetCourseScoreColumnsList($cid);
        $courseScoreColums=array();
        foreach ($scList as $scProp)
        {
            $courseScoreColums[$scProp['scid']]=$scProp['scid'].','.$scProp['cscfactor'];
        }
        $tid = $term->LastTermID();
        $counts = $course->AddCourse($ccode.'2',$tid,$lid,$pid,$clid,$majors,$courseScoreColums,$cgender,$descriptive_score,$final_capacity,$days_times,NULL,$exam_place,$ccourse_start_date,$ccomment,$aid);
        if ($counts==1)
        {
            $new_cid = $course->LastCourseID();
            $cs = new ManageCourseStudents();
            $query = " WHERE `".$table_prefix."courses`.`cid`=$cid ";
            $courseStudentList = $cs->GetCourseStudentList($query,'');
            foreach ($courseStudentList as $csInfo)
                $cs->AddCourseStudent($csInfo['uid'],$new_cid,$csInfo['lvid'],$aid);
        }
    }
$str    =   "select * from  tableName";  //replacing * by table columns is a good practice

$result =    $conn->query($str);

while($arr = $result->fetch_array(MYSQLI_ASSOC);)
{
   $strr1  = "  INSERT INTO  tableName (  `id` , `title` , `des` ) //add more
            VALUES (  '".$arr['id']."2',  '".$arr['something']."'   //add as you require
          ";

   if($conn->query($strr1) === false) {
      trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $conn->error, E_USER_ERROR);
     } 
 }