1

I try to use a php array in a postgres select statement.

I tried:

$sql = "SELECT * FROM some_table WHERE string_field IN ($1) AND other_field = $2;";

$result = pg_query_params($conn, $sql, array(implode(',', $my_arr), $other_field));

But when i run it nothing returns. (when I hardtype everything in postgres, something will be returned)

user2628641
  • 2,035
  • 4
  • 29
  • 45

1 Answers1

1

Strings needs single quotes as I know. Concat the elements of array like this:

$data = ['a','b','c','d'];
$x = "'" . implode("','", $data) . "'";
var_dump($x);

Result:

'a','b','c','d'
vaso123
  • 12,347
  • 4
  • 34
  • 64