Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id 4AB1F47641B for ; Fri, 3 May 2002 10:01:52 -0400 (EDT) Received: from VL-MS-MR001.sc1.videotron.ca (relais.videotron.ca [24.201.245.36]) by postgresql.org (Postfix) with ESMTP id B6C33475CF0 for ; Fri, 3 May 2002 10:00:29 -0400 (EDT) Received: from pippo.videotron.ca ([24.201.61.95]) by VL-MS-MR001.sc1.videotron.ca (Netscape Messaging Server 4.15) with ESMTP id GVJG8T01.QXG; Fri, 3 May 2002 10:00:31 -0400 Message-Id: <5.1.0.14.2.20020503092500.00ad3e98@pop.videotron.ca> X-Sender: vltazczw@pop.videotron.ca X-Mailer: QUALCOMM Windows Eudora Version 5.1 Date: Fri, 03 May 2002 10:00:25 -0400 To: Chris From: "P. Jourdan" Subject: Re: sql command Cc: pgsql-php@postgresql.org 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> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Archive-Number: 200205/30 X-Sequence-Number: 1162 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