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')