Answer the question
In order to leave comments, you need to log in
How to use mysql functions in ActiveRecord when searching for a record?
Good evening everyone.
I am looking for a user by his unique token. In a normal request, everything looks like this:
SELECT login FROM `users` WHERE MD5(CONCAT(`users`.`id`, Yii::app()->params->salt )) = $token
$criteria=new CDbCriteria;
$criteria->select='login';
$criteria->condition = 'hash=:hash';
$criteria->params = [
':hash' => "MD5(CONCAT(`users`.`id`, '" . Yii::app()->params->salt . "'))"
];
$arUser = (new User)->find($criteria);
Answer the question
In order to leave comments, you need to log in
Alas, it is necessary to use CDbExpression. Yes, compatibility between databases is being killed, but what can you do.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question