简体   繁体   English

SQLSTATE [HY000]:执行查询后出现一般错误

[英]SQLSTATE[HY000]: General error after execute query

My update query sets the correct value but returns the following error in Yii2: 我的update查询设置了正确的值,但在Yii2中返回以下错误:

Error: SQLSTATE[HY000]: General error 错误: SQLSTATE[HY000]: General error

Update query: 更新查询:

$query =Yii::$app->db
        ->createCommand('
    UPDATE fc_dore_reg 
    INNER JOIN fc_dore ON fc_dore.id = fc_dore_reg.dore_id SET fc_dore_reg.pay_all = 1 
    WHERE fc_dore_reg.user_id = "'.$user_id.'"
')->queryAll();

Why is this error occuring when fc_dore_reg.pay_all = 1 is set correctly? 正确设置fc_dore_reg.pay_all = 1时,为什么会发生此错误?

You should use execute() 您应该使用execute()

Yii::$app->db
        ->createCommand('
            UPDATE fc_dore_reg 
            INNER JOIN fc_dore ON fc_dore.id = fc_dore_reg.dore_id 
            SET fc_dore_reg.pay_all = 1 
            WHERE fc_dore_reg.user_id = "'.$user_id.'"')
        ->execute();

Remember that queryAll() Executes the SQL statement and returns ALL rows at once but there are no rows to return in an update .. 请记住,queryAll()执行SQL语句并一次返回所有行,但没有行要在更新中返回。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM