gpt4 book ai didi

php - 由于假定的 MySQL 语法错误,Shell 脚本出错

转载 作者:行者123 更新时间:2023-11-29 00:12:43 24 4
gpt4 key购买 nike

我编写了一个 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

注意:变量之前在脚本的开头定义,但我没有在这里列出它们,因为我觉得它们是无关紧要的。

最佳答案

由于问题已通过评论解决,以下是我打开日志记录的方式:

我将查询存储为一个变量:$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);

关于php - 由于假定的 MySQL 语法错误,Shell 脚本出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24316142/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com