复制prestashop DB中的表格

时间:2016-04-19 09:10:57

标签: php mysql sql prestashop

我试图复制 Prestashop id_lang不同的表名。

我想要实现的是我将名称复制到同一个表格中,从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 

1 个答案:

答案 0 :(得分:1)

以下是您的查询:

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";