Re: Type cast in PHP PDO (does not work like in Java?)

From: Raymond O'Donnell <rod(at)iol(dot)ie>
To: Alexander Farber <alexander(dot)farber(at)gmail(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Type cast in PHP PDO (does not work like in Java?)
Date: 2017-08-05 16:38:39
Message-ID: 6379d292-a27a-f83b-c1b7-063a8f6b9fe7@iol.ie
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 05/08/17 16:58, Alexander Farber wrote:
> Good evening,
>
> with PostgreSQL 9.6.3 and JDBC 42.1.1.jre7 types can be casted when
> calling a stored function:
>
> final String sql = "SELECT words_buy_vip(?::text, ?::int,
> ?::text, ?::text, ?::float, ?::inet)";
>
> try (Connection db = DriverManager.getConnection(DATABASE_URL,
> DATABASE_USER, DATABASE_PASS);
> PreparedStatement st = db.prepareStatement(sql)) {
> st.setString(2, sid);
> st.setInt(1, SOCIAL_FACEBOOK);
> // etc.
> st.executeQuery();
> }
>
> But with PHP 5.4.16 on CentOS 7 Linux the types can not be casted (and
> strangely the statement is just not being executed without any error
> being reported) and the "::text", "::int" and "::inet" should be removed
> from the placeholders as in:

I think PDO uses a colon in named parameters, so maybe that's causing
problems. You could try casting like this:

select words_buy_vip(cast(? as text), cast(? as int), .....);

Ray.

--
Raymond O'Donnell :: Galway :: Ireland
rod(at)iol(dot)ie

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Igor Korot 2017-08-05 17:46:20 Re: Lifetime of PQexecPrepared() returned value
Previous Message Alexander Farber 2017-08-05 15:58:23 Type cast in PHP PDO (does not work like in Java?)