문제

I've been attempting to use phpactiverecord for a project.. and I'm struggling to see if I can actually pass a mysql function through any of its native updating methods. I'm a little surprised I couldn't find an answer to this question anywhere else =P.

EDIT: After a year of using the framework, a simple answer is to simply do: $object->date = 'now'

도움이 되었습니까?

해결책

If I understand correctly you want to call NOW() to update a timestamp field. There are several options.

다른 팁

While I could be off base, but I think that directly you don't pass sql into active record. However my understanding of active record (from working with Yii's version of active record) is that active record is built upon a CDbConnection, from the class CActiveRecord:

/** * @var CDbConnection the default database connection for all active record classes. * By default, this is the 'db' application component. * @see getDbConnection */

in Yii to access this you can use the code:

$sql = 'select * from mytable';
$rows = Yii::app()->db->createCommand($sql)->queryAll();

if you aren't using Yii you'll have to lookup how to access the db object.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top