Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8621227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:46:24+00:00 2026-06-12T06:46:24+00:00

I have a model type that was generated from a mysql table that has

  • 0

I have a model type that was generated from a mysql table that has address data and also a spatial POINT field named “coordinates”. When a model is created or updated I want to geocode the address and store the latitude and longitude coordinates in the POINT field.

My understanding is the way to do this is to geocode the address in the model’s beforeSave method. I have done this and have the coordinates in an associative array. Now my question is how can I insert this data into my coordinates field? This is what I’m trying:

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();
}

When I do this I get the following error:

CDbCommand failed to execute the SQL statement: SQLSTATE[HY093]:
Invalid parameter number: number of bound variables does not match
number of tokens. The SQL statement executed was: 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)’))

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T06:46:25+00:00Added an answer on June 12, 2026 at 6:46 am

    Try this instead

     $this->coordinates = new CDbExpression("GeomFromText(:point)",
            array(':point'=>'POINT('.$coords['lat'].' '.$coords['lng'].')'));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have generated a strongly-type view from a model class that I have created
I have a DropDownList populated with a SelectList generated from (an anonymous type) that
I have a Model that contains a List of a custom type. I want
I have a view model that contains a Product class type and an IEnumerable<
I have model: # encoding: utf-8 class Tag include Mongoid::Document field :name, type: String
I have a model: class SimpleAction include Mongoid::Document field :set_date, :type => Date and
In entity framework I have an Entity 'Client' that was generated from a database.
I have a EDM that was wizard generated from an SQL 2005 Express database.
Suppose I have a domain model that has 1:1 correspondence to the physical model.
I have two objects of the same class (Model) type. I want to check

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.