使用PHP将LONGBLOB文件从一个表复制到另一个表

时间:2018-08-28 13:49:57

标签: php database

//SELECT DB
$con = mysqli_connect("localhost","root","","database");

//FETCH DATA FROM TABLE1
$check= mysqli_query($con, "select * from user_info_tbl where username = '$user_check' ") or die(mysqli_error($con));

$row = mysqli_fetch_array($check); 
$username = $row["username"];
$picture = $row["picture"]; //my way of getting the blob file to table1

$content = addslashes($_POST["content"]); //this is from an input tag

//INSERTING DATA TO TABLE2 INCLUDING THE BLOB FILE
$query1="INSERT INTO postings (prof_pic,user_name, content)
        VALUES ('$picture','$username','$content')";

这是我的桌子1

|ID    |username     |    picture
+------+-------------+-----------------+
|1     |user1        | [BLOB -7.3 KiB] |
|2     |user2        | [BLOB -2.4 KiB] |
|3     |user3        | [BLOB -6.0 KiB] |

这是我的桌子2

|ID    |prof_pic     | username  |  content
+------+-------------+-----------+-----------+
|1     |             | user1     |this is my post
|2     |             | user2     |hello world
|3     |             | user2     |lets go

但是只有用户名和内容被插入到table2中。我想获取table1上的“图片”以复制到table2上的“ prof_pic”上,其中table1.username = table2.username

有人可以帮我,将Blob文件插入到另一个表中吗? 提前致谢。

PS。我只是一个初学者。抱歉,代码混乱。

0 个答案:

没有答案