Newbie, using yii framework 1.1, today when practicing the CRUD update operation of database DAO, I encountered a problem, please look at the code:
It means that I want to update the record with name value lishenglong in the database table to smart. The database table record is as follows:
That is, batch update, the following 4 rows of records are updated, but this is not the case.
The execution result is that only the first row is updated. What is the situation? ?
I turned on the log to view the executed sql statement. The statement is as follows:
I found the reason. When binding parameters, my update condition of name='lishenglong' was overwritten. My update condition was name='lishenglong', but when parsed, it became name='smart'. , name='smart' is actually the new value I want to update, not the update condition. Am I clear? Please also ask the aunt who has been through the pit to tell me the reason and give me the solution. I am very grateful~
Newbie, using yii framework 1.1, today when practicing the CRUD update operation of database DAO, I encountered a problem, please look at the code:
It means that I want to update the record with name value lishenglong in the database table to smart. The database table record is as follows:
That is, batch update, the following 4 rows of records are updated, but this is not the case.
The execution result is that only the first row is updated. What is the situation? ?
I turned on the log to view the executed sql statement. The statement is as follows:
I found the reason. When binding parameters, my update condition of name='lishenglong' was overwritten. My update condition was name='lishenglong', but when parsed, it became name='smart'. , name='smart' is actually the new value I want to update, not the update condition. Am I clear? Please also ask the aunt who has been through the pit to tell me the reason and give me the solution. I am very grateful~
View the update method of system.db.CDbCommand in the Yii1.1 Class Reference Manual. The method prototype is as follows:
<code>public integer update(string $table, array $columns, mixed $conditions='', array $params=array ( ))</code>
There is a special explanation for $params
<code>Do not use column names as parameter names here. They are reserved for $columns parameter.</code>
This means don’t use field names as placeholder names.
The solution is
<code>'name=:cname',array(':cname'=>'lishenglong')</code>