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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
Boget, Chris wrote:<br>
<blockquote type="cite"
cite="mid4040BBE81A9AD411BD27009027887A7C0431BF@tiger.wild.net">
<meta http-equiv="Content-Type" content="text/html; ">
<meta name="Generator"
content="MS Exchange Server version 5.5.2650.12">
<title>PHP & PostgreSQL</title>
<p><font size="2">I'm switching from a MySQL environment to PGSQL and
I'm</font> <br>
<font size="2">going through and trying to learn the differences
between the</font> <br>
<font size="2">two. I've come across some issues that I can't seem
to find the</font> <br>
<font size="2">answers to in the docs or on the web. I'm hoping
someone can</font> <br>
<font size="2">help me out.</font></p>
</blockquote>
I'll try.<br>
<blockquote type="cite"
cite="mid4040BBE81A9AD411BD27009027887A7C0431BF@tiger.wild.net">
<p> </p>
<p><font size="2">* MySQL has a function to reset the result set so
that it can be</font> <br>
<font size="2">iterated through again - mysql_data_seek(). I don't
see that there</font> <br>
<font size="2">is a similar function for PGSQL. Is that true? If
so, in order to</font> <br>
<font size="2">reset the result set you have to perform the query
again? Isn't</font> <br>
<font size="2">that a waste of resources?</font></p>
</blockquote>
In the PGSQL fetch functions, you usualy pass the row number<br>
as a parameter. So you can iterate through the table as many times<br>
as you want, just create a counter to control the iteration.<br>
<blockquote type="cite"
cite="mid4040BBE81A9AD411BD27009027887A7C0431BF@tiger.wild.net">
<p><font size="2">* For PGSQL, you can get the database name, the
field name</font> <br>
<font size="2">even the *host name* but you can't get the table name
from a</font> <br>
<font size="2">particular query?</font></p>
</blockquote>
I'm afraid that's true, at least I don't know such a function.<br>
<br>
But I advise you to try the PEAR DB extension from PHP,<br>
instead of using directly the database functions.<br>
<br>
my regards,<br>
<br>
<pre class="moz-signature" cols="72">--
Diogo de Oliveira Biazus
<a class="moz-txt-link-abbreviated" href="mailto:diogo@ikono.com.br">diogo@ikono.com.br</a>
Ikono Sistemas e Automação
<a class="moz-txt-link-freetext" href="http://www.ikono.com.br">http://www.ikono.com.br</a>
</pre>
</body>
</html>
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.
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.
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
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 Microsofts
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