我有一个模型类型,是从包含地址数据和空间
我的理解是,在模型的
当我这样做时,我会得到以下错误:
CDbCommand无法执行SQL语句:SQLSTATE [HY093]:无效参数数量:绑定变量的数量与令牌的数量不匹配。 执行的SQL语句是:INSERT INTO
POINT
字段(名为“coordinates”)的mysql表生成的。当创建或更新模型时,我希望对地址进行地理编码,并将纬度和经度坐标存储在POINT
字段中。我的理解是,在模型的
beforeSave
方法中进行地址地理编码的方法。我已经这样做了,并在一个关联数组中获得了坐标。现在我的问题是,如何将这些数据插入到我的坐标字段中?以下是我的尝试:public function beforeSave()
{
$singleLineAddress = $this->getSingleLineAddress();
$coords = Geocoder::getCoordinates($singleLineAddress);
// WORKS: using the following line works to insert POINT(0 0)
//$this->coordinates = new CDbExpression("GeomFromText('POINT(0 0)')");
// DOESN'T WORK: using the following line gives an error
$this->coordinates = new CDbExpression("GeomFromText('POINT(:lat :lng)')",
array(':lat' => $coords['lat'], ':lng' => $coords['lng'] ));
return parent::beforeSave();
}
当我这样做时,我会得到以下错误:
CDbCommand无法执行SQL语句:SQLSTATE [HY093]:无效参数数量:绑定变量的数量与令牌的数量不匹配。 执行的SQL语句是:INSERT INTO
place
(city
, state
, name
, street
, postal_code
, phone
, created
,coordinates
) VALUES (:yp0, :yp1, :yp2, :yp3, :yp4, :yp5,UTC_TIMESTAMP(),GeomFromText('POINT(:lat:lng)'))