gpt4 book ai didi

php和mysql将记录从一个表复制到另一个

转载 作者:可可西里 更新时间:2023-11-01 06:31:01 24 4
gpt4 key购买 nike

我想通过将记录从一个表移动到另一个表来存档学生。这是我尝试使用的代码:

<?php
ini_set('memory_limit', '100M');
$sql="Select * from `register` where student_id=".$student_id;
$result=mysql_query($sql);
$row=mysql_fetch_array($result);

//Call the function to archive the table
//Function definition is given below
archive_record(archive,$row);

//Once you archive, delete the record from original table

$sql = "Delete from `register` where student_id=".$student_id;
mysql_query($sql);


function archive_record($archived_tablename,$row)
{
$sql = "insert into $archived_tablename values(";
$i=0;
while($i<(count($row)-1))
{
$sql.="'".$row[$i]."',";
}
$i=$i+1;

$sql.="'".$row[$i]."'";
$sql.=")";

mysql_query($sql);
return true;
}

我遇到的问题是出现错误:

fatal error :第 XX 行/archive-student.php 内存不足(已分配 80478208)(已尝试分配 80216043 字节)

除了有一个名为 archive 的列并从 0 更改为 1 之外,是否有任何不同的方法可以做到这一点?这是因为我有 30-50 页选择表的记录。 :)

最佳答案

INSERT INTO archive_table
SELECT * FROM original_table WHERE id = 1

就这么简单。

如果表格有不同的列号、其他布局等,您也必须指定列 :too

INSERT INTO archive_table(field1, field2, field3)
SELECT field7, field8, field9 FROM original_table WHERE id = 1

关于php和mysql将记录从一个表复制到另一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9640881/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com