2014-06-19 46 views
1

我已经写了我的web应用程序(Magento的)重置客户的密码PHP脚本:当我尝试从shell执行shell脚本示数出因认为MySQL的语法错误

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

然而, :

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 

注:变量是先前d在脚本开始时就有所定义,但我没有在这里列出,因为我觉得它们是无关的。

+3

你会得到什么,如果你打印整个查询? –

+0

伟大的问题,让我登录并看看。 – sparecycle

+0

也许问题是唯一一个没有引号? entity_id = $ customer_id和 – Matt

回答

1

既然问题与意见解决了,这是我如何打开日志记录:

我保存查询作为一个变量:$查询

$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);