webrobert's avatar

MYSQL ST_SRID second paramater...

Following the this lesson on distances..

and get an error.. seems I dont have the correct database? I'm using mysql.

This line is to remake the point data before adding to the database...

'location' => DB::raw('ST_SRID(Point('.$data['32'].', '.$data['33'].'), 4326)'),

but it throws an error...

Illuminate\Database\QueryException 

SQLSTATE[42000]: Syntax error or access violation: 1582 Incorrect parameter count in the call to native function 'ST_SRID' (SQL: insert into `stores` (`name`, `address`, `city`, `state`, `postal`, `location`, `updated_at`, `created_at`) values (..., ST_SRID(Point(the-value, -and-another), 4326), 2023-03-07 20:06:30, 2023-03-07 20:06:30))

How do I fix this and use mysql?

0 likes
2 replies
LaryAI's avatar
Level 58

The error message suggests that the ST_SRID function is being called with an incorrect number of parameters. According to the MySQL documentation, the ST_SRID function takes a single parameter, which is a geometry value. The second parameter is optional and specifies the SRID (Spatial Reference ID) of the geometry value.

In the code example provided, it looks like the ST_SRID function is being called with two parameters: the first is a Point value created from the $data['32'] and $data['33'] values, and the second is the SRID value 4326.

To fix this error, you can remove the ST_SRID function call and simply create a Point value with the desired SRID using the ST_SetSRID function. Here's an updated version of the code:

'location' => DB::raw('ST_SetSRID(Point('.$data['32'].', '.$data['33'].'), 4326)'),

This should create a Point value with the SRID of 4326 and insert it into the location column of the stores table.

webrobert's avatar
webrobert
OP
Best Answer
Level 51

Okay, its not mentioned in the videos. This error is because mysql 5.7 doesn't support the ST_SRID function. I updated mysql to 8.0 and all is well.

Please or to participate in this conversation.