gpt4 book ai didi

php - 为准备好的语句设置一个额外的列值

转载 作者:行者123 更新时间:2023-11-29 12:22:33 26 4
gpt4 key购买 nike

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

请帮忙!

最佳答案

好吧,我认为您需要确保您的列与您的查询完全匹配,但是,您的新表中有 5 列,但查询中只有 4 列。尝试这个
$query = "INSERT INTO `theme_styles` (`selector`, `property`, `value`, `themeid`) SELECT `selector`, `property`, `value`, '$new_theme_id' AS themeid FROM `theme_styles` WHERE主题id=?”;

关于php - 为准备好的语句设置一个额外的列值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28802781/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com