我编写了一个PHP脚本,用于重置我的Web应用程序(Magento)的客户密码:
$write->query("update customer_entity_varchar set value='$password'
where entity_id=$customer_id and attribute_id in (select attribute_id from eav_attribute
where attribute_code='password_hash' and entity_type=1)");
但是,当我尝试从shell执行时:
php script.php
它会产生以下错误:
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]:
Syntax error or access violation: 1064 You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the right
syntax to use near 'and attribute_id in (select attribute_id from eav_attribute where attribute_code' at line 1' in /chroot/home/html/lib/Zend/Db/Statement/Pdo.php:228
注意:变量以前是在脚本开头定义的,但我没有在这里列出,因为我觉得它们是无关紧要的。
答案 0 :(得分:1)
由于问题是通过评论解决的,以下是我打开日志记录的方式:
我将查询存储为变量:$ query
$query = "update customer_entity_varchar set value='$password' where entity_id=$customer_ID and attribute_id in (select attribute_id from eav_attribute where attribute_code='password_hash' and entity_type_id=1)";
$write->query($query);
$file = 'query.txt';
// Open the file to get existing content
$current = file_get_contents($file);
// Append a new person to the file
$current .= $query . "\n";
// Write the contents back to the file
file_put_contents($file, $current);