11

I'm trying to prepare a query from PHP like:

pg_prepare($con, "prep", "select * from test where tid in (1ドル)");

and then execute it with:

$strpar = "3,4,6,8,10";
pg_execute($con, "prep", array($strpars));

The problem is that I cannot pass a series of values built as prepare expects a fixed number of parameters. Is there any way to make the parameters dynamic?

Erwin Brandstetter
186k28 gold badges463 silver badges636 bronze badges
asked Dec 14, 2013 at 8:10

1 Answer 1

16

Use an array to represent the series of values:

pg_prepare($con, "prep", "select * from test where tid=ANY(1ドル::int[])");
$strpar = "{3,4,6,8,10}";
pg_execute($con, "prep", array($strpars));

The cast to int[] in the query might even be superfluous if the planner is able to infer the type by itself.

answered Dec 14, 2013 at 13:21

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.