gpt4 book ai didi

php - 在 prestashop DB 的表内复制

转载 作者:行者123 更新时间:2023-11-29 02:50:17 27 4
gpt4 key购买 nike

我正在尝试复制 id_langPrestashop 中不同的表的名称。

我想要实现的是,我将名称复制到同一个表中,从 id_lang=6 到 name where id_lang=8

我有工作正常的 SQL 查询,但我想用 PHP 查询代替,这样我就可以在上面放一个 cron。

谁能帮帮我?

UPDATE ps_product_lang a
INNER JOIN ps_product_lang b
ON b.id_product = a.id_product
AND b.id_lang = 6
AND a.id_product > 2218
SET a.name = b.name
WHERE a.id_lang = 8

最佳答案

这是您的查询:

Db::getInstance(_PS_USE_SQL_SLAVE_)->execute(
"UPDATE `" . _DB_PREFIX_ . "product_lang` a
INNER JOIN `" . _DB_PREFIX_ . "product_lang` b
ON b.id_product = a.id_product
AND b.id_lang = 6
AND a.id_product > 2218
SET a.name = b.name
WHERE a.id_lang = 8"
);

如果你想创建一个 cron,这里是你的 php 文件:

<?php

// Put the real path to config.inc.php depending on the location of this file
include_once ('../../config/config.inc.php');

try {
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->execute(
"UPDATE `" . _DB_PREFIX_ . "product_lang` a
INNER JOIN `" . _DB_PREFIX_ . "product_lang` b
ON b.id_product = a.id_product
AND b.id_lang = 6
AND a.id_product > 2218
SET a.name = b.name
WHERE a.id_lang = 8"
);
} catch (PrestaShopDatabaseException $e) {
// You might need to get some more informations on this error
// $error = $e->getMessage();
$result = false;
}

echo $result ? "ok" : "ko";

关于php - 在 prestashop DB 的表内复制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36713823/

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