0

I have crateio set up and it's working fine using the PDO class.

I'm, trying to get a set of geopoints into the db using binds.

I have tried foreach but doesn't seem to work, I've tried this - which also doesn't work.

The geopoint column is set to geo_point_array.

$route="[[30.33333, -6.13336],[30.33333, -6.13336]]"; 

$db = new Database; 

$db->Query("insert into geopoints (id, longlat, name) values ('33',?,'pat')"); 

$db->bind(1, $route); 
$db->execute();

How do I add this set of cordinates to the db?

Thanks

2 Answers 2

2

GeoPoint is not supported as a native type in Crate's PDO driver yet, however you can use an double ARRAY.

From the Crate documentation:

Columns with the geo_point are represented and inserted using a double array in the following format: [lon_value, lat_value]

I also strongly recommend to do parameter substitution for the other values.

use Crate\PDO\PDO;

$route = [[30.33333, -6.13336], [30.33333, -6.13336]];

$db = new PDO('crate:...'); 
$stmt = $db->query("insert into geopoints (id, longlat, name) values (?, ?, ?)"); 

$stmt->bind(1, 33, PDO::PARAM_INT); 
$stmt->bind(2, $route, PDO::PARAM_ARRAY); 
$stmt->bind(3, 'pat', PDO::PARAM_STR); 

$stmt->execute();
0

PDO::query returns PDOStatement:

$route="[[30.33333, -6.13336],[30.33333, -6.13336]]"; 

//If Dateabase is a sublcass of PDO
//$db = new Database; 
$db = new PDO(...); 

$stmt = $db->query("insert into geopoints (id, longlat, name) values ('33',?,'pat')"); 

$stmt->bind(1, $route, PDO::PARAM_STR); 
$stmt->execute();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.