我有這個查詢它複製現有的行: 我需要設置另一列themeid
爲$new_theme_id
值。我如何將此添加到此查詢中?設置一個額外的列值到準備好的語句
$existing_theme_id = 1234;
$new_theme_id = 5678;
$query = "INSERT INTO theme_styles SELECT selector, property, value, '$new_theme_id' AS themeid FROM theme_styles WHERE themeid=?";
try { $stmt = $dbh->prepare($query); $stmt->execute(array($theme_id)); } catch(PDOException $ex) { echo 'Query failed: ' . $e->getMessage(); exit; }
此查詢不起作用。
我的表結構:
id int(6) AUTO_INCREMENT
themeid int(4)
selector varchar(100) latin1_swedish_ci
property varchar(50) latin1_swedish_ci
value mediumtext latin1_swedish_ci
請幫幫忙!
嘗試這樣的:' 「INSERT INTO theme_styles(SELECT選擇,屬性值從theme_styles WHERE的ThemeID =?),$ new_theme_id」;'? – 2015-03-02 04:54:14
現在的代碼究竟是什麼問題?它會給出錯誤的結果嗎?拋出異常? – Mureinik 2015-03-02 04:56:48
@jogesh_pi:不起作用,我甚至試過:'$ query =「INSERT INTO theme_styles(SELECT selector,property,value FROM theme_styles WHERE themeid =?),'$ new_theme_id'AS themeid」;'。沒有錯誤消息被拋出.. – 2015-03-02 05:03:05