在prestashop数据库中的表内复制


Copy inside a table in prestashop DB

Im试图复制一个表的名称,其中id_langPrestashop中不同。

我想实现的是,我将同一个表中的名称从id_lang=6复制到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";