加入Yii class CDBCriteria?

时间:2012-02-09 17:55:39

标签: sql yii

有没有人可以帮我将以下SQL语句(在我的数据库中工作)转换为Yii框架CDbCriteria类格式?

这是我的SQL:

SELECT cars。*,3963 * acos(cos(弧度(53.376217))* cos(弧度(car_dealers.latitude))* cos(弧度(-1.499595) - 弧度(car_dealers.longitude))+ sin(弧度( 53.376217))* sin(弧度(car_dealers.latitude)))AS距汽车JOIN car_dealers ON cars.company_id = car_dealers.company_id WHERE cars.make ='Fiat'AND cars.model ='Punto'ORDER BY距离;

这是我的Yii尝试:

$criteria= new CDbCriteria;
$criteria->alias = 'cars';
$criteria->select= 'cars.*, 3963 * acos(cos(radians(53.376217)) * cos(radians(car_dealers.latitude)) * cos(radians(-1.499595) - radians(car_dealers.longitude)) + sin(radians(53.376217)) * sin(radians(car_dealers.latitude))) AS distance';
$criteria->join='JOIN car_dealers ON cars.company_id=car_dealers.company_id';
$criteria->condition= 'make=:make AND model=:model'; 
$criteria->params= array('[:make] => Fiat,[:model] => Punto')
$criteria->order='distance';

非常感谢任何可以提供帮助的人! :)

1 个答案:

答案 0 :(得分:0)

你这里有一个错字

$criteria->params= array('[:make] => Fiat,[:model] => Punto')

应该是:

$criteria->params= array(':make' => 'Fiat',':model' => 'Punto')