문제

I need to pass an array of strings in a parameterized query. I tried the following but it doesn't work at all.

$params = array( array('bob','andrew','larry') );
pg_query_params($conn, 'SELECT * FROM table1 WHERE field = ANY($1)', $params)

I've seen solutions that converts the array to a string and then uses string_to_array to convert the input to an array on the database side, but as those strings are input from users this could end badly, even if I used a delimiter other than a comma. I'd rather use a cleaner solution for this, if possible.

Is there a way to keep this query parameterized and pass an array to it, without resorting to converting the data to a string?

By the way, I'm using PostgreSQL 8.3

도움이 되었습니까?

해결책

pgsql.so is linked to libpq which does not have this capability.

Internally, it would need to serialize an array into string anyway.

libpqtypes has this capability built in, but I'm now aware of any PHP libraries using it.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top