Re: Connecting PostgreSQL db using Pear - Mailing list pgsql-php

From Vince Vielhaber
Subject Re: Connecting PostgreSQL db using Pear
Date
Msg-id Pine.BSF.4.40.0210041333470.81546-100000@paprika.michvhf.com
Whole thread Raw
In response to Re: Connecting PostgreSQL db using Pear  (Devrim GUNDUZ <devrim@oper.metu.edu.tr>)
Responses Re: Connecting PostgreSQL db using Pear  (Devrim GUNDUZ <devrim@oper.metu.edu.tr>)
List pgsql-php
On Fri, 4 Oct 2002, Devrim GUNDUZ wrote:

>
> Hi,
>
> (sorry for the late response...)
>
> On 2 Oct 2002, Andrew McMillan wrote:
>
> > Can you confirm that the postmaster is started with support for TCP
> > connections?  It is possible that in other instances you are connecting
> > via unix sockets.
>
> Good point. Tried this connection parameters in two different servers.
> One of them uses Unix domain sockets, the other has a tcp_ip port open...
>
> Anyway, does someone has an example of PostgreSQL + Pear?

Strangely enough, yes.  I just did it this week.


// include pear's db stuff
    require_once 'DB.php';

// set up your data source
    $dsn = "pgsql://vev@localhost/mydatabase";

// connect to your data source
    $db = DB::connect($dsn, false);
    if (DB::isError($db)) {
        die ($db->getMessage());
    }

// make your query
    $query = "select a from foo";

    $res = $db->query($query);
    if (DB::isError($res)) {
        echo("$query<P>\n");
        die ($res->getMessage());
    }


// display your results
    while ($row = $res->fetchRow())
        echo("$row[0]<br>\n");

// disconnect and return
    $db->disconnect();
    return;


Quite simple actually.  I was surprised.  The docs make it look
a whole lot harder than it is.

Vince.
--
==========================================================================
Vince Vielhaber -- KA8CSH    email: vev@michvhf.com    http://www.pop4.net
         56K Nationwide Dialup from $16.00/mo at Pop4 Networking
      http://www.camping-usa.com      http://www.cloudninegifts.com
   http://www.meanstreamradio.com       http://www.unknown-artists.com
==========================================================================




pgsql-php by date:

Previous
From: Devrim GUNDUZ
Date:
Subject: Re: Connecting PostgreSQL db using Pear
Next
From: Devrim GUNDUZ
Date:
Subject: Re: Connecting PostgreSQL db using Pear