>I've been using MySQL/PHP for quite some time.  Several months ago, I
>wanted to port a project over to PostgreSQL.  I found everything about pg
>(eg the website, documentation, installation process) far less straight
>ahead than MySQL.  So much so, that I didn't get around to actually
>installing pg.

I actually found PostgreSQL more straight-forward, since the arguments are
required.
(Or used to be.)  So I better understood what was going on in PostgreSQL.

Not as many examples "out there" but, really, changing:

mysql_query($query) to
pg_exec($connection, $query)

in reading the examples is not that tricky...

Oh well.  Different tastes for different folks.

>Plus, as others have pointed out, the supporting functions in PHP aren't
>as powerful/diverse.  For example, there's no insert id function.

Yes, there *IS* such a function, but it's a two-step process.

$oid = pg_getlastoid() followed by a SELECT ... where oid = $oid

http://www.php.net/manual/en/function.pg-last-oid.php

OID stands for "Object ID", and every PosgreSQL object has a unique OID. 
Every row, every Large Object, every everything.

Whoops.  Just double-checked, and apparently pSQL 7.2 doesn't *have* to have
OIDs for everything.  This could get interesting, folks...  A quick perusal
of the PHP Docs makes me say:
Only get rid of the optional OID if you are 100% sure you'll never need go
use pg_last_oid() or you'll be in deep trouble.

You do *NOT* want to "just use the oid as my own id" however.  OIDs can
change when you export/import database data, if you're not careful, and it's
just bad form to use that internal ID as your own.

PostgreSQL (and any SQL database) would be completely un-usable (*) if there
wasn't some way to reliably get the last tuple inserted from your own
connection.

Kinda funny that never made it into SQL92 :-)

(*) Yeah, okay, you can generate your own unique ID before the insert, and
then SELECT on that to get the auto-generated ID...  Might as well not
bother with an auto-generated ID, then, eh?

-- 
Like Music?  http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to