0

I have problem inserting geographic data into sqlserver database. This is my array:

this is my controller

UPDATED

  function add()
  {
    $Code = $this->input->post('Code');
    $Description = $this->input->post('Description');
    $Data= $this->input->post('Data');
    $Data2= $this->input->post('Data2');
    $Data3= $this->input->post('Data3');
    $Latitude = $this->input->post('Latitude');
    $Longitude = $this->input->post('Longitude');       
    $Highway_Type = $this->input->post('Highway_Type');

    $data = array(
    'Code' => $Code, 
    'Description' => $Description,
    'Data' => $Data,
    'Data2' => $Data2,
    'Data3' => $Data3,
    'Latitude' => $Latitude,
    'Longitude' => $Longitude,
    'Highway_Type' => $Highway_Type,
    'GeoLocation' => 'geography::Point('.$Latitude.', '.$Longitude.', 4326)',               
    );

    $parent_id = create_data('Table', $data, $user_id);
  }

The geolocation is the problem because it's geography datatype. I can't insert because I got this:

this is screenshot of error

How can I get rid of that thing ' ' for geography type shouldn't have that thing ' '?

this is function for create data

function create_data($model_name, $data, $user_id)
{
    $ci =& get_instance();
    $ci->load->database();

    $ci->db->insert($model_name, $data);

    return $ci->db->insert_id();
}
  • what do you mean? you don't want to insert `geography::Point(2.992054, 101.769510, 4326)` ? – Dray Jan 27 '16 at 05:32
  • `geography::Point()` is it any method to get data. – Vinie Jan 27 '16 at 06:43
  • @Dray i want to insert but i dont know how to get rid the upper colon ('geo..') in array – farahdalilah Jan 27 '16 at 06:49
  • @farahdalilah array values are always enclosed with `' '` but it won't be saved in the db with `' '`. What do you want to save exactly? An example please? – Dray Jan 27 '16 at 08:18
  • dear @Dray I want to save this data 'geography::Point(2.992054, 101.769510, 4326)' into sqlserver . i have update my answer – farahdalilah Jan 27 '16 at 09:30
  • Please note there's a clean distinction between strings and literals. You cannot use prepared statements to insert the latter. But there's no way to help you fix some code you haven't shared. – Álvaro González Jan 27 '16 at 09:35
  • @farahdalilah show full code where you insert your array to DB. – Dray Jan 27 '16 at 09:38
  • Any error when you put it this way `geography::Point($Latitude, $Longitude, 4326),`? – Tpojka Jan 27 '16 at 12:42
  • @Tpojka yes, this is the error 'Fatal error: Class 'geography' not found' . don't know how to make it correct. – farahdalilah Jan 27 '16 at 14:04
  • Do you have/use somewhere such a class? – Tpojka Jan 27 '16 at 14:15
  • @Tpojka I dont have any class of geography. because geography is a data type for sql server. is it should have a class for that? – farahdalilah Jan 27 '16 at 14:18
  • No. My questions were here to denominate some CI regular errors. I just wondered if needed to execute some calculation before insert. It seems like string in table to me. – Tpojka Jan 27 '16 at 14:21
  • i dont really know about ci, sorry but i think it doesnt need calculation because its working when i insert manually in db something like this' insert into table (latitude,longitude) values ('01.000','101.000', geography::Point(01.000, 101.000, 4326))' – farahdalilah Jan 27 '16 at 14:31
  • i have update my question @ÁlvaroGonzález is it okay? – farahdalilah Jan 27 '16 at 14:37
  • i have update my question @Dray . is it okay? – farahdalilah Jan 27 '16 at 14:37

0 Answers0