php and mysql copy record from one table to another(php 和 mysql 将记录从一张表复制到另一张表)
问题描述
我想通过将记录从一张表移动到另一张表来归档学生.这是我尝试使用的代码:
I would like to archive a student by moving the record from one table to another. This is the code I am trying to use:
<?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;
}
我遇到的问题是我收到错误:
Problem I am having is that i am getting error:
致命错误:第 XX 行/archive-student.php 中的内存不足(分配 80478208)(试图分配 80216043 字节)
除了有一个名为存档的列并从 0 更改为 1 之外,还有其他方法可以做到这一点吗?这是因为我有 30-50 页选择表的记录.:)
Is there any different way to do this, except for have a column called archive and changing from 0 to 1? This is because I have 30-50 pages selecting the table's records. :)
推荐答案
INSERT INTO archive_table
SELECT * FROM original_table WHERE id = 1
就这么简单.
如果表格有不同的列号、其他布局等,您也必须指定列:
If tables have different column number, other layout etc., you will have to specify columns :too
INSERT INTO archive_table(field1, field2, field3)
SELECT field7, field8, field9 FROM original_table WHERE id = 1
这篇关于php 和 mysql 将记录从一张表复制到另一张表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:php 和 mysql 将记录从一张表复制到另一张表


基础教程推荐
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 在多维数组中查找最大值 2021-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01