Thread: PHP & PostgreSQL

PHP & PostgreSQL

From
"Boget, Chris"
Date:

I'm switching from a MySQL environment to PGSQL and I'm
going through and trying to learn the differences between the
two.  I've come across some issues that I can't seem to find the
answers to in the docs or on the web.  I'm hoping someone can
help me out.

* MySQL has a function to reset the result set so that it can be
iterated through again - mysql_data_seek().  I don't see that there
is a similar function for PGSQL.  Is that true?  If so, in order to
reset the result set you have to perform the query again?  Isn't
that a waste of resources?

* For PGSQL, you can get the database name, the field name
even the *host name* but you can't get the table name from a
particular query?

Any info would be greatly appreciated!

Chris

Re: PHP & PostgreSQL

From
Diogo de Oliveira Biazus
Date:
Boget, Chris wrote:
<blockquote type="cite"
 cite="mid4040BBE81A9AD411BD27009027887A7C0431BF@tiger.wild.net">

  <meta name="Generator"
 content="MS Exchange Server version 5.5.2650.12">
  PHP & PostgreSQL
  I'm switching from a MySQL environment to PGSQL and
I'm
  going through and trying to learn the differences
between the
  two.  I've come across some issues that I can't seem
to find the
  answers to in the docs or on the web.  I'm hoping
someone can
  help me out.

I'll try.
<blockquote type="cite"
 cite="mid4040BBE81A9AD411BD27009027887A7C0431BF@tiger.wild.net">

  * MySQL has a function to reset the result set so
that it can be
  iterated through again - mysql_data_seek().  I don't
see that there
  is a similar function for PGSQL.  Is that true?  If
so, in order to
  reset the result set you have to perform the query
again?  Isn't
  that a waste of resources?

In the PGSQL fetch functions, you usualy pass the row number
as a parameter. So you can iterate through the table as many times
as you want, just create a counter to control the iteration.
<blockquote type="cite"
 cite="mid4040BBE81A9AD411BD27009027887A7C0431BF@tiger.wild.net">
  * For PGSQL, you can get the database name, the
field name
  even the *host name* but you can't get the table name
from a
  particular query?

I'm afraid that's true, at least I don't know such a function.

But I advise you to try the PEAR DB extension from PHP,
instead of using directly the database functions.

my regards,

--
Diogo de Oliveira Biazus
diogo@ikono.com.br
Ikono Sistemas e Automação
http://www.ikono.com.br

Re: PHP & PostgreSQL

From
"Jules Alberts"
Date:
Op 30 Dec 2002 (10:52), schreef Diogo de Oliveira Biazus <diogo@ikono.com.br>:
> Boget, Chris wrote:
> > I'm switching from a MySQL environment to PGSQL and I'm
<snip>
> But I advise you to try the PEAR DB extension from PHP,
> instead of using directly the database functions.

Also have a look at adodb and choose which you like most.

Re: PHP & PostgreSQL

From
"Chris Boget"
Date:
> In the PGSQL fetch functions, you usualy pass the row number
> as a parameter. So you can iterate through the table as many times
> as you want, just create a counter to control the iteration.

Hmm, I guess I could do it that way.  I just prefer using

while( $row = pg_fetch_array()) {

>   * For PGSQL, you can get the database name, the field name
>   even the *host name* but you can't get the table name from a
>   particular query?
> I'm afraid that's true, at least I don't know such a function.

Ok, that's what I was afraid of...

> But I advise you to try the PEAR DB extension from PHP,
> instead of using directly the database functions.

I am starting to use PEAR and will from here on out.  The switch
over is a nightmare having to change all the code (and the logic).

Chris


Re: PHP & PostgreSQL

From
"Matthew Nuzum"
Date:
The Adodb database abstraction library is free to use and works very
well.  I like it even in projects that will only use postgres.  It makes
programming databases easier, will do a lot of the mundane work for you,
and if you have different projects that use different databases, it
allows you to use the same adodb commands.

You can find all kinds of information about adodb including a function
reference, tutorials and download links at
http://php.weblogs.com/adodb_manual

Keep in mind that this library was originally modeled after Microsoft’s
Ado library.  Therefore, it does not bear a strong resemblance to the
native php db functions.  An interesting side effect though is that I
recently had to write a simple Visual Basic application and found that I
already knew most of the database stuff because of my php adodb
experience.  :-)

Matthew Nuzum
www.followers.net
matt@followers.net
-----Original Message-----
From: Boget, Chris [mailto:chris@wild.net]
Sent: Monday, December 30, 2002 5:14 AM
To: 'php-general@lists.php.net'
Cc: 'pgsql-general@postgresql.org'
Subject: PHP & PostgreSQL

I'm switching from a MySQL environment to PGSQL and I'm
going through and trying to learn the differences between the
two.  I've come across some issues that I can't seem to find the
answers to in the docs or on the web.  I'm hoping someone can
help me out.
* MySQL has a function to reset the result set so that it can be
iterated through again - mysql_data_seek().  I don't see that there
is a similar function for PGSQL.  Is that true?  If so, in order to
reset the result set you have to perform the query again?  Isn't
that a waste of resources?
* For PGSQL, you can get the database name, the field name
even the *host name* but you can't get the table name from a
particular query?
Any info would be greatly appreciated!
Chris


Re: PHP & PostgreSQL

From
CoL
Date:
Check the manual, it is very very good.

Boget, Chris wrote, On 12/30/2002 11:06 AM:
> * MySQL has a function to reset the result set so that it can be
> iterated through again - mysql_data_seek().  I don't see that there
> is a similar function for PGSQL.  Is that true?  If so, in order to
> reset the result set you have to perform the query again?  Isn't
> that a waste of resources?
pg_fetch ...  has a second parameter
array pg_fetch_array ( resource result [, int row [, int result_type]])
...
row is row (record) number to be retrieved. First row is 0.
$b=0;
while(pg_fetch_row($result,$b++)){} so you can seek where ever you want.


> * For PGSQL, you can get the database name, the field name
> even the *host name* but you can't get the table name from a
> particular query?
now check postgres manual, or once the php manual, how to get table
names, or etc.
http://www.php.net/manual/en/ref.pgsql.php
Comment:
passion at monkey dot org
27-Jun-2001 07:53

....
for tables:
SELECT relname FROM pg_class WHERE relname !~ '^pg_' and relkind='r';

C.