如何将图像数据从一个表移动到另一个表?

时间:2011-12-25 21:49:12

标签: php mysql sql

<?php
include ("connect.php");
$id=@addslashes($_GET['id']);
$image=@mysql_query("select * from tipuranibasti where id = $id");
$image_row=@mysql_fetch_assoc($image);  
$name=@$image_row['name'];
$date=@$image_row['date']; 
$msg=@$image_row['msg'];
$image=addslashes(@file_get_contents($image_row['image']));


if(@mysql_query("insert into puranibasti values('','$name','$date','$msg','$image')"))
{
echo "image has been inserted successfully";
} else
{
echo "problem inserting the image";
}
?>

1我能将所有数据从tipuranibasti移动到表puranibasti除了图像可以任何人请帮助

2 个答案:

答案 0 :(得分:0)

也许您可以在单个sql语句中插入值,而不是选择+ insert:

if(
   @mysql_query("     
      insert into puranibasti  
      select '', name, date, msg, image 
      from tipuranibasti where id = $id"
  ")

答案 1 :(得分:0)

INSERT INTO target (id, name, date, msg, image)
SELECT '', name, date, msg, image FROM source
WHERE source.id = $id

这种方法可以防止你必须将sql值转换为php,然后从php转换回sql。