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

时间:2022-05-20 23:01:44

how do I combine the mysql insert and select statement into a prepared statement?? Will this part of the code help me to duplicate information into a database when I hit the "copy" button?

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

Thanks.

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 个解决方案

#1


0  

You don't have to combine anything. INSERT ... SELECT is a simple statement....

你不必结合任何东西。 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 = ?"
    );

#1


0  

You don't have to combine anything. INSERT ... SELECT is a simple statement....

你不必结合任何东西。 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 = ?"
    );