mysql插入并在准备好的语句中选择

时间:2013-08-04 18:36:23

标签: php mysql

如何将mysql insert和select语句组合成一个预准备语句?当我点击“复制”按钮时,这部分代码是否会帮助我将信息复制到数据库中?

感谢。

INSERT INTO assignment_speeches_copy (id, subject, body, tags, image)
SELECT * FROM assignment_speeches
WHERE id = $id";

$stmt = $mysqli->prepare("INSERT INTO assignment_speeches_copy VALUES (?,?,?,?,?)"); (how do I continue?)

1 个答案:

答案 0 :(得分:0)

你不必合并任何东西。 INSERT ... SELECT是一个简单的陈述......

$stmt = $mysqli->prepare(
    "INSERT INTO assignment_speeches_copy (id, subject, body, tags, image) 
        SELECT (id, subject, body, tags, image) 
           FROM assignment_speeches 
           WHERE id = ?"
    );