2014-06-19 72 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);