Re: PHP PDO getting data from pgSQL stored function

Michael Schmidt <[email protected]> Fri, 08 Nov 2013 20:26:12 +0100
Newsgroups gmane.comp.db.postgresql.php
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--------------090705030905020809030909
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hi,

sorry for the late response.

I did it with the solution posted by Jonah.

It is not necessary for me to return a table(...) because i want to 
return the structure which is already defined in my database so i can 
use SETOF RECORD as return type. So i use the real table to define the 
return of my function.

PDO select works just like a normal select on a table.

Thank you.

Am 03.11.2013 17:06, schrieb Jonah H. Harris:
> On Sat, Nov 2, 2013 at 11:54 AM, Michael Schmidt <[email protected] 
> <mailto:[email protected]>> wrote:
>
>     i need to do a ugly select which i dont want to place in my php code.
>     I use PDO all the time.
>
>
> All database access from our application is functionalized using 
> either PL/pgSQL or SQL functions.
>
>     I want to return a structure which is the same as a table i have
>     created.
>
>
> CREATE FUNCTION blah (IN param 1, ..., IN param n, OUT param 1, ... 
> OUT param n) RETURNS SETOF RECORD
>
>     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)?
>
>
> Just do a SELECT * FROM blah(...); as a normal PDO query.
>
> -- 
> Jonah H. Harris
> Blog: http://www.oracle-internals.com/


--------------090705030905020809030909
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">Hi,<br>
      <br>
      sorry for the late response.<br>
      <br>
      I did it with the solution posted by Jonah. <br>
      <br>
      It is not necessary for me to return a table(...) because i want
      to return the structure which is already defined in my database so
      i can use SETOF RECORD as return type. So i use the real table to
      define the return of my function.<br>
      <br>
      PDO select works just like a normal select on a table.<br>
      <br>
      Thank you.<br>
      <br>
      Am 03.11.2013 17:06, schrieb Jonah H. Harris:<br>
    </div>
    <blockquote
cite="mid:CADUqk8VG3sKPWAqczKeE1xk_zcho8_+BajrYu16tDrAMXzV=kQ@mail.gmail.com"
      type="cite">
      <div dir="ltr">On Sat, Nov 2, 2013 at 11:54 AM, Michael Schmidt <span
          dir="ltr">&lt;<a moz-do-not-send="true"
            href="mailto:[email protected]" target="_blank">[email protected]</a>&gt;</span>
        wrote:<br>
        <div class="gmail_extra">
          <div class="gmail_quote">
            <blockquote class="gmail_quote" style="margin:0 0 0
              .8ex;border-left:1px #ccc solid;padding-left:1ex">i need
              to do a ugly select which i dont want to place in my php
              code.<br>
              I use PDO all the time.<br>
            </blockquote>
            <div><br>
            </div>
            <div>All database access from our application is
              functionalized using either PL/pgSQL or SQL functions.</div>
            <div>&nbsp;</div>
            <blockquote class="gmail_quote" style="margin:0 0 0
              .8ex;border-left:1px #ccc solid;padding-left:1ex">
              I want to return a structure which is the same as a table
              i have created.<br>
            </blockquote>
            <div><br>
            </div>
            <div>CREATE FUNCTION blah (IN param 1, ..., IN param n, OUT
              param 1, ... OUT param n) RETURNS SETOF RECORD</div>
            <div>
              <br>
            </div>
            <blockquote class="gmail_quote" style="margin:0 0 0
              .8ex;border-left:1px #ccc solid;padding-left:1ex">Now my
              question, how can i return that and access it with PHP
              PDO?<br>
              Should I use a cursor or shoul I use the return of the
              function (if it is possible)?<br>
            </blockquote>
            <div><br>
            </div>
            <div>Just do a SELECT * FROM blah(...); as a normal PDO
              query.</div>
            <div><br>
            </div>
          </div>
          -- <br>
          Jonah H. Harris<br>
          Blog: <a moz-do-not-send="true"
            href="http://www.oracle-internals.com/" target="_blank">http://www.oracle-internals.com/</a>
        </div>
      </div>
    </blockquote>
    <br>
  </body>
</html>

--------------090705030905020809030909--