Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vd2Xy-0006BH-Uj for pgsql-php@arkaria.postgresql.org; Sun, 03 Nov 2013 18:37:15 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Vd2Xx-0000oL-Ib for pgsql-php@arkaria.postgresql.org; Sun, 03 Nov 2013 18:37:13 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vd2Xw-0000oF-N7 for pgsql-php@postgresql.org; Sun, 03 Nov 2013 18:37:12 +0000 Received: from mailout.ownit.se ([94.137.101.210] helo=spamgw1.ownit.se) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vd2Xr-0002ut-LW for pgsql-php@postgresql.org; Sun, 03 Nov 2013 18:37:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ownit.se; s=2010.dkim; h=received:received:content-type:mime-version:subject:from:in-reply-to:date:cc: content-transfer-encoding:message-id:references:to:x-mailer; bh=ktwXScfnjjZWKw2dQGZ8+HIRM4wV0gLKRyDkb+O4Qb0=; b=W7Jk3xpq2zqoo88/Fv9ZjWDkkFFlMCgMZDmL218V+ml6ySvaYto59DfuFskJWu3DIVVzexQcAqLi+ MaOb7g2TkJN+g5V1sIHtl4Cvjjl5lc8n4hT5mVwLzuNGe3Pw6QXrkSJAs4Btfkhec3QcBjhn4O0ho1 vfN3NHnYlSH1mSG0= Received: from mail.ownit.nu (unknown [109.104.0.111]) by mailout.ownit.se (Halon Mail Gateway) with ESMTPS; Sun, 3 Nov 2013 19:35:32 +0100 (CET) Received: from [192.168.1.6] (89-253-107-135.customers.ownit.se [89.253.107.135]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by mail.ownit.nu (Postfix) with ESMTPS id 158E0FD5D1; Sun, 3 Nov 2013 19:35:32 +0100 (CET) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 6.6 \(1510\)) Subject: Re: PHP PDO getting data from pgSQL stored function From: reiner peterke In-Reply-To: <5275203C.2090007@gmail.com> Date: Sun, 3 Nov 2013 19:35:01 +0100 Cc: pgsql-php@postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: References: <5275203C.2090007@gmail.com> To: Michael Schmidt X-Mailer: Apple Mail (2.1510) X-Pg-Spam-Score: -1.1 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-php Precedence: bulk Sender: pgsql-php-owner@postgresql.org Hi=20 basically create a function returning a table, then select * from function(= ) can be called from php. below is a complete sql language function i wrote returning a table. create or replace function show_privilege(p_grantee name) returns table(grantee name ,role_name name ,grantor name ,table_catalog name ,table_name name ,privilege_type varchar) as $$=20=20=20=20 select=20 AR.grantee::name ,AR.role_name::name ,RTG.grantor::name ,RTG.table_catalog::name ,RTG.table_name::name ,privilege_type=20 from=20=20 information_schema.applicable_roles AR left outer join=20 information_schema.role_table_grants RTG on (AR.role_name =3D RTG.gra= ntee) where=20 AR.grantee =3D p_grantee; $$ language sql; you'll notice the returns table defines the rows in the return. on one of my databases, if i run: select * from show_privilege('wuggly_ump_admin'); i get grantee | role_name | grantor | table_catalog | table_name | priv= ilege_type=20 ------------------+-----------+---------+---------------+------------+-----= ----------- wuggly_ump_admin | sys_user | | | |=20 (1 row) i hope that helps. reiner On 2 nov 2013, at 16:54, Michael Schmidt wrote: > Hi guys, >=20 > i need to do a ugly select which i dont want to place in my php code. > I use PDO all the time. >=20 > I want to return a structure which is the same as a table i have created. >=20 > I want to write it in pgSQL. >=20 > Now my question, how can i return that and access it with PHP PDO? > Should I use a cursor or shoul I use the return of the function (if it is= possible)? >=20 > Can someone provide a piece of example code? >=20 > Thanks for help >=20 >=20 > --=20 > Sent via pgsql-php mailing list (pgsql-php@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-php --=20 Sent via pgsql-php mailing list (pgsql-php@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-php