Yii update operation with parameters update failed it's weird.

Source: Internet
Author: User
Tags yii

Novice, with the YII Framework 1.1, today in the Practice database DAO's CRUD Update operation, encountered a problem, see the code:


It means I want to update the record with name value Lishenglong in the database table to smart, and the database table records as follows:


That is, batch update, the following 4 lines of records updated, but it is not the case,
The result of the execution is only the first line is updated, what is the situation??
I opened the log to view the execution of the SQL statement, with the following statement:

Find the reason, is the binding parameters, the update condition of my name= ' lishenglong ' update conditions covered, my update condition is name= ' Lishenglong ', the time of parsing into a name= ' smart ', name= ' Smart ' is actually the new value I want to update, not the update condition Ah, do not know I said understand? Please tell me the reason, and give me the solution, thank you.

Reply content:

Novice, with the YII Framework 1.1, today in the Practice database DAO's CRUD Update operation, encountered a problem, see the code:


It means I want to update the record with name value Lishenglong in the database table to smart, and the database table records as follows:


That is, batch update, the following 4 lines of records updated, but it is not the case,
The result of the execution is only the first line is updated, what is the situation??
I opened the log to view the execution of the SQL statement, with the following statement:

Find the reason, is the binding parameters, the update condition of my name= ' lishenglong ' update conditions covered, my update condition is name= ' Lishenglong ', the time of parsing into a name= ' smart ', name= ' Smart ' is actually the new value I want to update, not the update condition Ah, do not know I said understand? Please tell me the reason, and give me the solution, thank you.

View the Yii1.1 class reference manual for the System.db.CDbCommand Update method, the method prototype is as follows:

public integer update(string $table, array $columns, mixed $conditions='', array $params=array ( ))

Which $params a special statement

Do not use column names as parameter names here. They are reserved for $columns parameter.

This means that you do not use field names as placeholder names.
Workaround is

'name=:cname',array(':cname'=>'lishenglong')
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.