2013-08-04 102 views
0

如何將mysql插入和select語句組合到一個準備好的語句中?當我點擊「複製」按鈕時,這部分代碼是否可以幫助我將信息複製到數據庫中?mysql插入並在準備好的語句中選擇

謝謝。

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?) 

回答

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 = ?" 
    ); 
+0

那麼在prepare語句之後的bind參數呢?我需要它嗎? – user2646948

+0

是的,對於'id'值 –

+0

喜歡這個? $ stmt-> bind_param('i',$ id); – user2646948