【发布时间】:2011-11-13 21:49:22
【问题描述】:
我有一个用于 Magento 的自定义导入和更新产品脚本。 该脚本运行良好很长时间,我更改了脚本中的一些内容,但我没有更改的命令停止工作
这是停止工作的代码:
require_once("connArray.php");
$dbConfig = GetConn();
$db = Zend_Db::factory('Pdo_Mysql', $dbConfig);
$update = "UPDATE catalog_product_entity_decimal p_dec
SET p_dec.value = $dec_value
WHERE p_dec.entity_id = $entity_id AND p_dec.attribute_id = 64";
echo $update;
echo "<br>";
$result = $db->query($update);
var_dump($result);
echo "<br>";
输出是:
UPDATE catalog_product_entity_decimal p_dec SET p_dec.value = 30.8 WHERE p_dec.entity_id = 2 AND p_dec.attribute_id = 64
object(Zend_Db_Statement_Pdo)#451 (9) { ["_fetchMode:protected"]=> int(2) ["_stmt:protected"]=> object(PDOStatement)#440 (1) { ["queryString"]=> string(124) "UPDATE catalog_product_entity_decimal p_dec SET p_dec.value = 30.8 WHERE p_dec.entity_id = 2 AND p_dec.attribute_id = 64" } ["_adapter:protected"]=> object(Zend_Db_Adapter_Pdo_Mysql)#33 (12) { ["_pdoType:protected"]=> string(5) "mysql" ["_numericDataTypes:protected"]=> array(16) { [0]=> int(0) [1]=> int(1) [2]=> int(2) ["INT"]=> int(0) ["INTEGER"]=> int(0) ["MEDIUMINT"]=> int(0) ["SMALLINT"]=> int(0) ["TINYINT"]=> int(0) ["BIGINT"]=> int(1) ["SERIAL"]=> int(1) ["DEC"]=> int(2) ["DECIMAL"]=> int(2) ["DOUBLE"]=> int(2) ["DOUBLE PRECISION"]=> int(2) ["FIXED"]=> int(2) ["FLOAT"]=> int(2) } ["_defaultStmtClass:protected"]=> string(21) "Zend_Db_Statement_Pdo" ["_config:protected"]=> array(8) { ["host"]=> string(9) "localhost" ["username"]=> string(16) "***" ["password"]=> string(9) "***" ["dbname"]=> string(17) "***" ["driver_options"]=> array(1) { [1002]=> string(14) "SET NAMES UTF8" } ["charset"]=> NULL ["persistent"]=> bool(false) ["options"]=> array(2) { ["caseFolding"]=> int(0) ["autoQuoteIdentifiers"]=> bool(true) } } ["_fetchMode:protected"]=> int(2) ["_profiler:protected"]=> object(Zend_Db_Profiler)#20 (4) { ["_queryProfiles:protected"]=> array(0) { } ["_enabled:protected"]=> bool(false) ["_filterElapsedSecs:protected"]=> NULL ["_filterTypes:protected"]=> NULL } ["_defaultProfilerClass:protected"]=> string(16) "Zend_Db_Profiler" ["_connection:protected"]=> object(PDO)#32 (0) { } ["_caseFolding:protected"]=> int(0) ["_autoQuoteIdentifiers:protected"]=> bool(true) ["_allowSerialization:protected"]=> bool(true) ["_autoReconnectOnUnserialize:protected"]=> bool(false) } ["_attribute:protected"]=> array(0) { } ["_bindColumn:protected"]=> array(0) { } ["_bindParam:protected"]=> array(0) { } ["_sqlSplit:protected"]=> array(1) { [0]=> string(124) "UPDATE catalog_product_entity_decimal p_dec SET p_dec.value = 30.8 WHERE p_dec.entity_id = 2 AND p_dec.attribute_id = 64" } ["_sqlParam:protected"]=> array(1) { [0]=> string(124) "UPDATE catalog_product_entity_decimal p_dec SET p_dec.value = 30.8 WHERE p_dec.entity_id = 2 AND p_dec.attribute_id = 64" } ["_queryId:protected"]=> NULL }
脚本运行后,我检查了数据库,相关行没有改变。
我已将输出的查询复制到 phpMyAdmin,它在那里工作正常。
我在上述代码运行正常之前运行的一个选择命令,我在脚本中有另一个更新命令确实有效,所以它看起来不像是连接问题。
提前致谢。
///////////////////////////////更新//////// /////////////////////////////////////////p>
我已尝试将代码更改为:
$data = array(
'value' => $dec_value
);
$where[] = "entity_id = " . $entity_id;
$where[] = "attribute_id = 64";
$result = $db->update('catalog_product_entity_decimal', $data, $where);
var_dump($result);
echo "<br>";
但它仍然不起作用。 $result 输出为 int(1)。
我尝试添加 $db->beginTransaction() 和 $db->commit() (即使默认情况下,所有 Zend_Db 适配器类都在自动提交模式下运行)但我收到错误: "SQLSTATE[HY000]: 一般错误: 1205 Lock wait timeout exceeded; try restarting transaction"
【问题讨论】:
-
你在做什么错误检查?您是否尝试过在 phpMyAdmin 之类的界面中运行查询?
-
我在 phpMyAdmin 中运行它,它运行良好(行已更改)。我没有收到任何错误。
-
不确定zend是如何工作的,如果它与php PDO相同,但尝试更新而不是查询。 framework.zend.com/manual/en/zend.db.adapter.html,你也可以试试 $db->commit();除非您也告诉它,否则它似乎不会提交。它将尝试查询,但尚未提交。查看示例 #23 和 #31
-
尝试使用更新而不是查询,但没有帮助。尝试添加 $db->beginTransaction() 和 $db->commit() (即使您给出的文章说“默认情况下,所有 Zend_Db 适配器类都在自动提交模式下运行。”)但我收到错误:SQLSTATE [HY000]:一般错误:1205 超过锁定等待超时;尝试重启事务
-
我解决了这个问题。这是我的代码中的一个错误(我在价格变化之前加载了产品对象,并在价格变化之后保存了它,因此该对象具有旧价格......)