error when performing query with function

Silverstripe Version: 4.xx

Hello everyone,

I have database table name carrier with scheme like this :

         cargo                 |   name               |    

truck_1,truck_2,truck_3 CARGO1
truck_4,truck_5,truck_6 CARGO2
truck_1,truck_2,truck_5 CARGO3
truck_7,truck_8,truck_9 CARGO2

I’m using postgresql database, and this is the query :

SELECT "name" FROM carrier WHERE string_to_array('truck_1,truck_2',',') && string_to_array(cargo,',');

this code can be run successfully on database app.

But when I brought this code on silverstripe controller it cause error :

$str = 'truck_1,truck_2';
DB::query('SELECT "name" FROM "carrier" WHERE  string_to_array('.$str.',',') && string_to_array("cargo",',')');

Q : What’s mistake on my code?
please help me


Can you provide a bit of wider context here? Is there a reason you’re not using the Silverstripe ORM for your database queries? Are these things set up as DataObjects?

You have quoting errors, and PHP is telling you exactly that:

PHP Parse error:  syntax error, unexpected ',' in ...