pg.ddx.io pgsql-php@postgresql.org mailing list archive
help / color / mirror / Atom feedInquiry From Form [pgsql]
10+ messages / 7 participants
[nested] [flat]
* Inquiry From Form [pgsql]
@ 2002-11-15 22:24 William <DarkCancerian@netscape.net>
2002-11-17 10:43 ` Inquiry From Form [pgsql] brew@theMode.com
2002-11-18 17:07 ` Re: Inquiry From Form [pgsql] scott.marlowe <scott.marlowe@ihs.com>
0 siblings, 2 replies; 10+ messages in thread
From: William @ 2002-11-15 22:24 UTC (permalink / raw)
To: info@pgsql.com
I code with PHP and use it to communicate with MySQL, if I started using PostgreSQL would I have to change my coding to communicate with the database?
^ permalink raw reply [nested|flat] 10+ messages in thread
* Inquiry From Form [pgsql]
2002-11-15 22:24 Inquiry From Form [pgsql] William <DarkCancerian@netscape.net>
@ 2002-11-17 10:43 ` brew@theMode.com
2002-11-18 04:48 ` Re: Inquiry From Form [pgsql] Budi Rianto <brianto@freenet.de>
2002-11-18 17:12 ` Re: Inquiry From Form [pgsql] scott.marlowe <scott.marlowe@ihs.com>
1 sibling, 2 replies; 10+ messages in thread
From: brew@theMode.com @ 2002-11-17 10:43 UTC (permalink / raw)
To: pgsql-php
On Fri, 15 Nov 2002, William wrote:
> I code with PHP and use it to communicate with MySQL, if I started using
> PostgreSQL would I have to change my coding to communicate with the
> database?
Probably, but only slightly.
I changed my DB from MySQL to PostgreSQL and had to change each SQL call
slightly. It seems to me the difference was PostgreSQL needs to know the
number of rows gotten and then loop through them with a for loop, with
MySQL I was able to use a while loop without checking the number of rows
first.
It could have been my inexperience that caused me to miss the obvious,
though.
In perl there is the DBI module and php has DBX. With it you use a common
calling cenvention across a bunch of Databases (FrontBase, Microsoft SQL
Server, MySQL, ODBC, PostgreSQL, Sybase-CT, Oracle)
From the manual at php.net:
-----------------------------------------------
The dbx functions allow you to access all supported databases using a
single calling convention. The dbx-functions themselves do not interface
directly to the databases, but interface to the modules that are used to
support these databases.
-----------------------------------------------
Of course, not all these DBs offer the same features, so you'd still not
be database independent unless you limit your DB calls to the common ones,
most likely SELECT, INSERT, UPDATE, and DELETE. But if you are using
MySQL maybe that's all you are doing anyway.......
I don't have the dbx module available on my machine and since I'm
committed to using (and learning more about) PostgreSQL I don't use the
dbx. But it seems it would be a good way to go......
Maybe someone else will chime in with more info.
brew
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: Inquiry From Form [pgsql]
2002-11-15 22:24 Inquiry From Form [pgsql] William <DarkCancerian@netscape.net>
2002-11-17 10:43 ` Inquiry From Form [pgsql] brew@theMode.com
@ 2002-11-18 04:48 ` Budi Rianto <brianto@freenet.de>
1 sibling, 0 replies; 10+ messages in thread
From: Budi Rianto @ 2002-11-18 04:48 UTC (permalink / raw)
To: pgsql-php
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Sunday 17 November 2002 05:43 pm, you wrote:
> On Fri, 15 Nov 2002, William wrote:
> > I code with PHP and use it to communicate with MySQL, if I started using
> > PostgreSQL would I have to change my coding to communicate with the
> > database?
>
> Probably, but only slightly.
>
> I changed my DB from MySQL to PostgreSQL and had to change each SQL call
> slightly. It seems to me the difference was PostgreSQL needs to know the
> number of rows gotten and then loop through them with a for loop, with
> MySQL I was able to use a while loop without checking the number of rows
> first.
>
[snip]
Using PostgreSQL 7.2 and PHP 4.1.2 in Linux, I found that some code is
becoming similar with the MySQL+PHP. For instance, you don't need to know the
numrows first to do a loop that display a query result.
New PostgreSQL+PHP way:
while($display=pg_fetch_array($getquery))
{
...
}
MySQL way :
while($display=mysql_fetch_array($getquery))
{
...
}
You can also use pg_numrows() instead of pg_num_rows() and some other 'new'
syntax that are like mysql way.
HTH
Budi.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iD8DBQE92HE1ZVSaxFm5xCIRAr1pAKCTnSD+hUoXe3+L+XXDONwhne49uACgtkGZ
CsVGw+0Y9nji8MZj8D50e7s=
=3lBF
-----END PGP SIGNATURE-----
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: Inquiry From Form [pgsql]
2002-11-15 22:24 Inquiry From Form [pgsql] William <DarkCancerian@netscape.net>
2002-11-17 10:43 ` Inquiry From Form [pgsql] brew@theMode.com
@ 2002-11-18 17:12 ` scott.marlowe <scott.marlowe@ihs.com>
1 sibling, 0 replies; 10+ messages in thread
From: scott.marlowe @ 2002-11-18 17:12 UTC (permalink / raw)
To: brew@theMode.com; +Cc: pgsql-php
On Sun, 17 Nov 2002 brew@theMode.com wrote:
>
> On Fri, 15 Nov 2002, William wrote:
>
> > I code with PHP and use it to communicate with MySQL, if I started using
> > PostgreSQL would I have to change my coding to communicate with the
> > database?
>
> Probably, but only slightly.
>
> I changed my DB from MySQL to PostgreSQL and had to change each SQL call
> slightly. It seems to me the difference was PostgreSQL needs to know the
> number of rows gotten and then loop through them with a for loop, with
> MySQL I was able to use a while loop without checking the number of rows
> first.
>
> It could have been my inexperience that caused me to miss the obvious,
> though.
The ability to use the
while ($row = pg_fetch_array(res)){
}
construct wasn't included in PHP until somewhere around 4.1 or 4.2 I
think.
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: Inquiry From Form [pgsql]
2002-11-15 22:24 Inquiry From Form [pgsql] William <DarkCancerian@netscape.net>
@ 2002-11-18 17:07 ` scott.marlowe <scott.marlowe@ihs.com>
2002-11-18 17:48 ` Re: Inquiry From Form [pgsql] Keary Suska <hierophant@pcisys.net>
1 sibling, 1 reply; 10+ messages in thread
From: scott.marlowe @ 2002-11-18 17:07 UTC (permalink / raw)
To: William <DarkCancerian@netscape.net>; +Cc: info@pgsql.com; Marc G. Fournier <scrappy@hub.org>; pgsql-php
On Fri, 15 Nov 2002, William wrote:
> I code with PHP and use it to communicate with MySQL, if I started
> using PostgreSQL would I have to change my coding to communicate with
> the database?
Not really. The only issue is if you used MySQL proprietary stuff.
There's a lot of things in MySQL that are workarounds for it not being a
transactional database that won't work in Postgresql, but using the
"right" method (i.e. a transaction or ANSI SQL) will work just fine.
The only other thing to change is your mysql_xxx commands to pgsql_xxx
commands.
Also, Postgresql doesn't have a pgsql_lastinsert_id like MySQL, instead,
you do it like this:
(Warning pseudocode... :-)
begin;
insert into table yada (field1, field2) values (val1, val2);
select currval('yada_seq');
insert into table yada_child (field1, field2, y_id) values (val1, val2,
y_id);
commit;
i.e. you use currval('seqname') to find out what the id was that was just
inserted.
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: Inquiry From Form [pgsql]
2002-11-15 22:24 Inquiry From Form [pgsql] William <DarkCancerian@netscape.net>
2002-11-18 17:07 ` Re: Inquiry From Form [pgsql] scott.marlowe <scott.marlowe@ihs.com>
@ 2002-11-18 17:48 ` Keary Suska <hierophant@pcisys.net>
0 siblings, 0 replies; 10+ messages in thread
From: Keary Suska @ 2002-11-18 17:48 UTC (permalink / raw)
To: pgsql-php
on 11/18/02 10:07 AM, scott.marlowe@ihs.com purportedly said:
>> I code with PHP and use it to communicate with MySQL, if I started
>> using PostgreSQL would I have to change my coding to communicate with
>> the database?
>
> Not really. The only issue is if you used MySQL proprietary stuff.
> There's a lot of things in MySQL that are workarounds for it not being a
> transactional database that won't work in Postgresql, but using the
> "right" method (i.e. a transaction or ANSI SQL) will work just fine.
There are other non-obvious gotchas. For instance, MySQL is much more
"tolerant" (to put it nicely) with column constraints. Take the following
table example:
CREATE TABLE some_table ( number INT NOT NULL, date DATE NOT NULL );
INSERT INTO some_table (date) VALUES ('2002-05-09');
-> MySQL accepts and sets "number" to 0
-> Postgres rejects with error (NOT NULL constraint)
Same goes if you insert only "number" and not date: Postgres rejects, MySQL
accepts with date value '0000-00-00'.
INSERT INTO some_table VALUES(1,'0000-00-00');
-> MySQL accepts
-> Postgres rejects with error--Postgres does not have empty dates or
times
INSERT INTO some_table VALUES(2, 2002-06-05);
-> MySQL accepts (has valid date constants)
-> Postgres rejects: dates must be quoted.
You should thoroughly test your application before making it live, as these
types of issues are not always obvious in the code. These gotchas are the
biggest problems for programmers who have learned SQL from MySQL, which,
IMHO, encourages sloppy SQL coding.
Other than these situations, the biggest difficulty with conversion is with
the database schema itself.
Keary Suska
Esoteritech, Inc.
"Leveraging Open Source for a better Internet"
^ permalink raw reply [nested|flat] 10+ messages in thread
* Inquiry From Form [pgsql]
@ 2003-05-15 21:37 Mark <mbergman@brunson.us>
2003-05-16 18:48 ` Re: Inquiry From Form [pgsql] scott.marlowe <scott.marlowe@ihs.com>
0 siblings, 1 reply; 10+ messages in thread
From: Mark @ 2003-05-15 21:37 UTC (permalink / raw)
To: info@pgsql.com
I have a Raq4i and I am trying to write PHP 4 to the PostgreSQL. But I keep getting undefined function: pg_connect() . I have the extension enabled and the PHP was compiled for postgreSQL. I do not understand what is going on?
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: Inquiry From Form [pgsql]
2003-05-15 21:37 Inquiry From Form [pgsql] Mark <mbergman@brunson.us>
@ 2003-05-16 18:48 ` scott.marlowe <scott.marlowe@ihs.com>
2003-05-16 19:47 ` Re: Inquiry From Form [pgsql] David Busby <busby@pnts.com>
0 siblings, 1 reply; 10+ messages in thread
From: scott.marlowe @ 2003-05-16 18:48 UTC (permalink / raw)
To: Mark <mbergman@brunson.us>; +Cc: info@pgsql.com; Marc G. Fournier <scrappy@hub.org>; pgsql-php
On Thu, 15 May 2003, Mark wrote:
> I have a Raq4i and I am trying to write PHP 4 to the PostgreSQL. But I
> keep getting undefined function: pg_connect() . I have the extension
> enabled and the PHP was compiled for postgreSQL. I do not understand
> what is going on?
If PHP says pg_connect is undefined, then the php the RAQ is running isn't
compiled for postgresql connectivity.
There are two common causes of this:
1: You compiled one build of PHP, the RAQ is running on another build.
2: You told PHP to build in postgresql connectivity, it couldn't find the
right header file, failed, writing an error message to the screen during
configuration, saying something along the lines of "could not find file
xxxxx.h" skipping postgresql configuration.
PHP will then happily build and run, without postgresql capabilities.
Try this:
write a web page with this in it:
<?php
phpinfo();
?>
Look through the page to see if it mentions postgresql. At the top will
be a list of all the switches it was configged with. If you have a
--with-pgsql there, but no pgsql section in phpinfo, then the configure
script couldn't find the right headers. Make sure you're running a fairly
late model version of both PHP and postgresql, as there was a bit of an
issue about a year ago when postgresql changed the name of one of it's
connection headers.
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: Inquiry From Form [pgsql]
2003-05-15 21:37 Inquiry From Form [pgsql] Mark <mbergman@brunson.us>
2003-05-16 18:48 ` Re: Inquiry From Form [pgsql] scott.marlowe <scott.marlowe@ihs.com>
@ 2003-05-16 19:47 ` David Busby <busby@pnts.com>
2003-05-16 19:51 ` Re: Inquiry From Form [pgsql] scott.marlowe <scott.marlowe@ihs.com>
0 siblings, 1 reply; 10+ messages in thread
From: David Busby @ 2003-05-16 19:47 UTC (permalink / raw)
To: pgsql-php
Look for the files libpq.h and also libpq-fe??? something like that. Those
are the PostgreSQL headers (.h) and libraires (.so) You'll have to have
those for pg_connect to work. When PHP is built it needs to know where
those are (in path with other includes and libraries? or something else
(/usr/local?/opt/postgre)).
/B
----- Original Message -----
From: "scott.marlowe" <scott.marlowe@ihs.com>
To: "Mark" <mbergman@brunson.us>
Cc: <info@pgsql.com>; "Marc G. Fournier" <scrappy@hub.org>;
<pgsql-php@postgresql.org>
Sent: Friday, May 16, 2003 11:48
Subject: Re: [PHP] Inquiry From Form [pgsql]
> On Thu, 15 May 2003, Mark wrote:
>
> > I have a Raq4i and I am trying to write PHP 4 to the PostgreSQL. But I
> > keep getting undefined function: pg_connect() . I have the extension
> > enabled and the PHP was compiled for postgreSQL. I do not understand
> > what is going on?
>
> If PHP says pg_connect is undefined, then the php the RAQ is running isn't
> compiled for postgresql connectivity.
>
> There are two common causes of this:
>
> 1: You compiled one build of PHP, the RAQ is running on another build.
>
> 2: You told PHP to build in postgresql connectivity, it couldn't find the
> right header file, failed, writing an error message to the screen during
> configuration, saying something along the lines of "could not find file
> xxxxx.h" skipping postgresql configuration.
>
> PHP will then happily build and run, without postgresql capabilities.
>
> Try this:
>
> write a web page with this in it:
>
> <?php
> phpinfo();
> ?>
>
> Look through the page to see if it mentions postgresql. At the top will
> be a list of all the switches it was configged with. If you have a
> --with-pgsql there, but no pgsql section in phpinfo, then the configure
> script couldn't find the right headers. Make sure you're running a fairly
> late model version of both PHP and postgresql, as there was a bit of an
> issue about a year ago when postgresql changed the name of one of it's
> connection headers.
>
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
^ permalink raw reply [nested|flat] 10+ messages in thread
* Re: Inquiry From Form [pgsql]
2003-05-15 21:37 Inquiry From Form [pgsql] Mark <mbergman@brunson.us>
2003-05-16 18:48 ` Re: Inquiry From Form [pgsql] scott.marlowe <scott.marlowe@ihs.com>
2003-05-16 19:47 ` Re: Inquiry From Form [pgsql] David Busby <busby@pnts.com>
@ 2003-05-16 19:51 ` scott.marlowe <scott.marlowe@ihs.com>
0 siblings, 0 replies; 10+ messages in thread
From: scott.marlowe @ 2003-05-16 19:51 UTC (permalink / raw)
To: David Busby <busby@pnts.com>; +Cc: pgsql-php
The way I "show" linux where to find the libs for postgresql is to edit
/etc/ld.so.conf to have a line like /usr/local/pgsql/lib and then run
ldconfig.
Otherwise PHP will compile, but apache won't start.
On Fri, 16 May 2003, David Busby wrote:
> Look for the files libpq.h and also libpq-fe??? something like that. Those
> are the PostgreSQL headers (.h) and libraires (.so) You'll have to have
> those for pg_connect to work. When PHP is built it needs to know where
> those are (in path with other includes and libraries? or something else
> (/usr/local?/opt/postgre)).
>
> /B
>
>
>
> ----- Original Message -----
> From: "scott.marlowe" <scott.marlowe@ihs.com>
> To: "Mark" <mbergman@brunson.us>
> Cc: <info@pgsql.com>; "Marc G. Fournier" <scrappy@hub.org>;
> <pgsql-php@postgresql.org>
> Sent: Friday, May 16, 2003 11:48
> Subject: Re: [PHP] Inquiry From Form [pgsql]
>
>
> > On Thu, 15 May 2003, Mark wrote:
> >
> > > I have a Raq4i and I am trying to write PHP 4 to the PostgreSQL. But I
> > > keep getting undefined function: pg_connect() . I have the extension
> > > enabled and the PHP was compiled for postgreSQL. I do not understand
> > > what is going on?
> >
> > If PHP says pg_connect is undefined, then the php the RAQ is running isn't
> > compiled for postgresql connectivity.
> >
> > There are two common causes of this:
> >
> > 1: You compiled one build of PHP, the RAQ is running on another build.
> >
> > 2: You told PHP to build in postgresql connectivity, it couldn't find the
> > right header file, failed, writing an error message to the screen during
> > configuration, saying something along the lines of "could not find file
> > xxxxx.h" skipping postgresql configuration.
> >
> > PHP will then happily build and run, without postgresql capabilities.
> >
> > Try this:
> >
> > write a web page with this in it:
> >
> > <?php
> > phpinfo();
> > ?>
> >
> > Look through the page to see if it mentions postgresql. At the top will
> > be a list of all the switches it was configged with. If you have a
> > --with-pgsql there, but no pgsql section in phpinfo, then the configure
> > script couldn't find the right headers. Make sure you're running a fairly
> > late model version of both PHP and postgresql, as there was a bit of an
> > issue about a year ago when postgresql changed the name of one of it's
> > connection headers.
> >
> >
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 2: you can get off all lists at once with the unregister command
> > (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
>
^ permalink raw reply [nested|flat] 10+ messages in thread
end of thread, other threads:[~2003-05-16 19:51 UTC | newest]
Thread overview: 10+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-11-15 22:24 Inquiry From Form [pgsql] William <DarkCancerian@netscape.net>
2002-11-17 10:43 ` brew@theMode.com
2002-11-18 04:48 ` Budi Rianto <brianto@freenet.de>
2002-11-18 17:12 ` scott.marlowe <scott.marlowe@ihs.com>
2002-11-18 17:07 ` scott.marlowe <scott.marlowe@ihs.com>
2002-11-18 17:48 ` Keary Suska <hierophant@pcisys.net>
2003-05-15 21:37 Inquiry From Form [pgsql] Mark <mbergman@brunson.us>
2003-05-16 18:48 ` scott.marlowe <scott.marlowe@ihs.com>
2003-05-16 19:47 ` David Busby <busby@pnts.com>
2003-05-16 19:51 ` scott.marlowe <scott.marlowe@ihs.com>
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