Re: CentOS 7.3, PostgreSQL 9.6.2, PHP 5.4 deliver array as string

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
Cc: Alexander Farber <alexander(dot)farber(at)gmail(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: CentOS 7.3, PostgreSQL 9.6.2, PHP 5.4 deliver array as string
Date: 2017-03-02 21:29:30
Message-ID: CAKFQuwbT--HEqbcdurGORaPdq-oCpHqND71xte1GSDiP0FUVBQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Mar 2, 2017 at 2:12 PM, Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
wrote:

> On 03/02/2017 12:45 PM, Alexander Farber wrote:
>
>> Good evening!
>>
>> I am calling this stored function -
>>
>> CREATE OR REPLACE FUNCTION words_get_board(
>> in_gid integer
>> ) RETURNS TABLE (
>> out_bid integer,
>> out_letters varchar[15][15],
>> out_values integer[15][15]
>> ) AS
>> $func$
>> SELECT
>> bid,
>> letters,
>> values
>> FROM words_games
>> WHERE gid = in_gid;
>>
>> $func$ LANGUAGE sql STABLE;
>>
>
> I am not seeing where you assign the results of your SELECT to the OUT
> parameters in the RETURNS TABLE. Nor do I see anything that turns the
> results into an array for those OUT parameters of array type.
>
>
​The function isn't the problem here - its in SQL language. Explicit
assignment is needed in pl/pgsql​.

>
>
>> by a PHP script -
>>
>> $sth = $dbh->prepare(SQL_GET_BOARD);
>> $sth->execute(array($gid));
>> if ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
>> $bid = $row['bid'];
>> $letters = $row['letters'];
>> $values = $row['values'];
>> }
>>
>> And then print the variable type -
>>
>> error_log('letters: ' . gettype($letters));
>>
>> and it is a "string" (instead of inspected array) with the following
>> content:
>>
>
Proper usage of PHP PDO is the concern - and outside my personal experience.

David J.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alexander Farber 2017-03-02 21:30:44 Re: CentOS 7.3, PostgreSQL 9.6.2, PHP 5.4 deliver array as string
Previous Message Adrian Klaver 2017-03-02 21:12:38 Re: CentOS 7.3, PostgreSQL 9.6.2, PHP 5.4 deliver array as string