Question

I have a table in the database and from this table i want to select 1 registration, using the UPDATE field, like:

select * from website order by update asc limit 1; 

is there a better way to load the registration than using the createCommand ?

and once i load the registration, how to i update the update field ?

I would prefer using Active Records.

Was it helpful?

Solution

You can select one row from a database table using your model with CDbCriteria and CActiveRecord like so:

$criteria = new CDbCriteria;
$criteria->order = '`update` ASC';
$model = Registration::model()->find($criteria);

Assuming that your model is called 'Registration'.

See the manuals for CDbCriteria's order property and CActiveRecord's find() method.

You can then edit the record just as you can with any other active record and save as you normally would, i.e.

$model->update = new CDbExpression('NOW()');
$model->save();

(or whatever you want to set the 'update' field to be)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top