Re: Connecting PostgreSQL db using Pear

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



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@xxxxxxxxxxx    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
==========================================================================





[Index of Archives]     [Postgresql General]     [Postgresql Admin]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Yosemite Backpacking]     [Postgresql Jobs]

  Powered by Linux