Re: MySQL --> PostgreSQL with PHP

From: Mark Kelly <pgsql(at)wastedtimes(dot)net>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: MySQL --> PostgreSQL with PHP
Date: 2010-10-09 14:51:59
Message-ID: 201010091551.59551.pgsql@wastedtimes.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hi.

On Saturday 09 Oct 2010 at 10:09 Helgi Örn Helgason wrote:

> On 9 October 2010 00:47, Mark Kelly <pgsql(at)wastedtimes(dot)net> wrote:
> > //============ START CODE ===================
> > // Connect to the PostgreSQL server
> > // Build a string to specify the connection parameters, NOT pass them as
> > args. $connectionString = "host=$hostName dbname=$databaseName ".
> > "user=$username password=$password";
> > if (!$connection = pg_connect($connectionString)) {
> > die("Cannot connect: ".pg_last_error());
>
> I forgot, this is my connection file:
>
> <?php
> $connstr = "host=localhost port=5432 dbname=database user=me password=yes";
> $dbh = pg_connect($connstr);
> if ($dbh)
> {
> echo "";
> }
> else
> {
> echo "No connection has been established<br>";
> }
> ?>
>
> Could there be a conflict between these two?

You only need to connect once, then use the connection handle for subsequent
database operations. If you have already made a connection by including your
connection script, there is no need to do it again. It won't hurt (other than
speed & memory), but isn't any point. Just miss out the connection in the
example code I sent. You still might want to change your connection script to
give you feedback on errors by including pg_last_error().

Cheers,

Mark

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Mark Kelly 2010-10-09 16:09:56 Query advice request
Previous Message Tom Lane 2010-10-09 14:47:21 Re: permissions failure to copy csv data