pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: P. Jourdan <pippo@videotron.ca>
To: Chris <csmith@squiz.net>
Cc: pgsql-php@postgresql.org
Subject: Re: sql command
Date: Fri, 03 May 2002 10:00:25 -0400
Message-ID: <5.1.0.14.2.20020503092500.00ad3e98@pop.videotron.ca> (raw)
In-Reply-To: <5.1.0.14.0.20020503090035.00aa8630@cooee.cybersydney.com.a u>
References: <5.1.0.14.2.20020502112451.00ac5080@mail.host45.com>

At 09:08 AM 5/3/2002 +1000, Chris Smith wrote:


>>Could someone explain to me why sql commands work in php with pgsql?
>
>?? Why wouldn't they? :P

I'm too new at this to understand. That's why I ask. What I don't 
understand is this: is sql generic as opposed to specific comands in mySQL 
and/or postgreSQL?
I now understand that in my problem below you are right, there was an 
sqlconnect function created as you suggested below.
Then, what would be the reason to use this sqlconnect function rather than 
pg_connect? Can't parameters be passed on to the pg_connect in the same way 
as they are passed on to the created sqlconnect? It seems like extra work 
or a bit of redundancy in creating a function that exists?

>It looks like the author wrote a function called 'sqlconnect' which takes 
>an array of data to (obviously) connect to the server.
>
>The function would probably look something like this:
>
>function sqlconnect($connectionarray) {
>pg_connect("host=$connectionarray['server'] user=$connectionarray['user'] 
>password=$connectionarray['password'] dbname=$connectionarray['database']");
>}
>
>(with more error checking and comments of course).

This is what I found (the MySQL references are there because the db was 
migrated from MySQL to PostgreSQL):

function SQLConnect($params='') {
     global $dbh;
     /*
      * MySQL equivalent:
      *  $dbh=mysql_pconnect( $db_server,$db_user,$db_password );
      */
     if(isset($params['server'])) {
         $connect="host=".$params['server'];
     }
     else {
         $connect='host=localhost';
     }
     if(isset($params['port'])) {
         $connect.=' port='.$params['port'];
     }
     else {
         $connect.=' port=5432';
     }
     if(isset($params['user'])) {
         $connect.=' user='.$params['user'];
     }
     if(isset($params['database'])) {
         $connect.=' dbname='.$params['database'];
     }
     if(isset($params['password'])) {
         $connect.=' password='.$params['password'];
     }
     $dbh=pg_pconnect($connect);
}

Thanks,
Philip




view thread (7+ messages)  latest in thread

Message-ID: <5.1.0.14.2.20020503092500.00ad3e98@pop.videotron.ca>
Permalink:  ../5.1.0.14.2.20020503092500.00ad3e98@pop.videotron.ca/
Also on:    postgresql.org/message-id/5.1.0.14.2.20020503092500.00ad3e98@pop.videotron.ca

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: pippo@videotron.ca, csmith@squiz.net
  Subject: Re: sql command
  In-Reply-To: <5.1.0.14.2.20020503092500.00ad3e98@pop.videotron.ca>
  References: <5.1.0.14.2.20020502112451.00ac5080@mail.host45.com> <5.1.0.14.2.20020503092500.00ad3e98@pop.videotron.ca>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox