在 prestashop DB 中复制 table
Copy inside a table in prestashop DB
我正在尝试复制 table 的名称,其中 id_lang
在 Prestashop 中有所不同。
我想要实现的是,我将 table 中的名称从 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";
我正在尝试复制 table 的名称,其中 id_lang
在 Prestashop 中有所不同。
我想要实现的是,我将 table 中的名称从 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";