I’m getting the following error, but ONLY when YII_DEBUG is set to false:
CDbCommand failed to execute the SQL statement: SQLSTATE[HY093]: Invalid parameter number
As soon as I set YII_DEBUG to true, everything works fine. The error and stack trace is:
The relevant methods from my Stop model look like this:
public function distance($latitude, $longitude, $units) {
$multiplier = Distance::getMultiplier($units);
$this->getDbCriteria()->mergeWith(array(
'select'=> array("`t`.*", "GeoDistance(location, POINT(:longitude_d, :latitude_d))*$multiplier as distance"),
'params' => array(
':latitude_d' => $latitude,
':longitude_d' => $longitude)
));
return $this;
}
public function nearby($latitude, $longitude, $distance = 0, $limit = -1, $units = Distance::UNIT_DEFAULT) {
$multiplier = Distance::getMultiplier($units);
$this->getDbCriteria()->mergeWith(array(
'condition' => "(:max_distance=0 OR GeoDistance(location, POINT(:longitude_n, :latitude_n))*$multiplier<:max_distance)",
'limit' => $limit,
'params' => array(
':max_distance' => $distance,
':latitude_n' => $latitude,
':longitude_n' => $longitude,
),
'order' => 'distance ASC'
));
return $this;
}
public function findNearby($latitude, $longitude, $distance = 0, $limit = -1, $units = Distance::UNIT_DEFAULT) {
return $this->distance($latitude, $longitude, $units)->nearby($latitude, $longitude, $distance, $limit, $units)->findAll();
}
}
Basically, I have a MySQL function called GeoDistance that calculates the distance between two latitude/longitude locations, and so what this is doing is finding all Stop’s that are within a certain distance. I thought maybe there was a conflict between the parameter names, so that’s why there’s the “_n” and “_d” postfix added. But that didn’t help.
Do parameters get bound differently when YII_DEBUG is set to false? I can’t figure out why this would only work when YII_DEBUG is true. Does anyone have any insight into this?
Thanks!