我有这个查询它复制现有的行: 我需要设置另一列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