简体   繁体   中英

SQLSTATE[HY000]: General error after execute query

My update query sets the correct value but returns the following error in Yii2:

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?

You should use 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 ..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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