pg.ddx.io pgsql-php@postgresql.org mailing list archive
help / color / mirror / Atom feedA valuable addition to PHP...
5+ messages / 4 participants
[nested] [flat]
* A valuable addition to PHP...
@ 2001-03-29 22:16 ` Andrew Hammond <drew@waugh.econ.queensu.ca>
2001-03-30 03:17 ` Re: A valuable addition to PHP... Stephen van Egmond <svanegmond@bang.dhs.org>
2001-03-30 10:54 ` Re: A valuable addition to PHP... Jesus Aneiros <aneiros@ucfinfo.ucf.edu.cu>
1 sibling, 2 replies; 5+ messages in thread
From: Andrew Hammond @ 2001-03-29 22:16 UTC (permalink / raw)
To: pgsql-php
As an unabashed hacker, I'd like to point out one addition that I
personally would really appreciate and find useful. Perl (and hence
mod-perl and/or mason based stuff) has DBI and zope offers their SQL
objects. Sadly, PHP's database stuff, while functional, is a fugly
mess. A layer of abstraction gives at least the illusion of database
independance. And while I certainly can (and have) written n'th tier
layers that encapsulate all the pg_* php function calls, I personally
don't _like_ having to do that kind of stuff. And given the choice,
I always go with a tool that will do it for me.
Of course yet-another-database-interface-layer while certainly a good
and usefull piece of engineering wouldn't be particularly new and
innovative. What _would_ be new and innovate, and maybe even impressive
is a database interface layer that provides not just the usual database
independant connect / query / result stuff but an organized, database
independant way of accessing metadata. Writing SQL queries that derive
metadata by futzing around with the pg_* tables works but is totally
non-portable. What I would really like to see is a database interface
layer that encapsulates all that nasty mess. Metadata and other
introspective stuff is a glaring ommission from SQL.
Well, you _did_ ask... :)
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: A valuable addition to PHP...
2001-03-29 22:16 ` A valuable addition to PHP... Andrew Hammond <drew@waugh.econ.queensu.ca>
@ 2001-03-30 03:17 ` Stephen van Egmond <svanegmond@bang.dhs.org>
2001-03-31 21:16 ` Re: A valuable addition to PHP... Andrew Hammond <drew@waugh.econ.queensu.ca>
1 sibling, 1 reply; 5+ messages in thread
From: Stephen van Egmond @ 2001-03-30 03:17 UTC (permalink / raw)
To: Andrew Hammond <drew@waugh.econ.queensu.ca>; +Cc: pgsql-php
On Thu, Mar 29, 2001 at 05:16:54PM -0500, Andrew Hammond wrote:
> independant way of accessing metadata. Writing SQL queries that derive
> metadata by futzing around with the pg_* tables works but is totally
> non-portable. What I would really like to see is a database interface
> layer that encapsulates all that nasty mess. Metadata and other
> introspective stuff is a glaring ommission from SQL.
I have written something that does this in two directions: listing out the
indices, tables, columns, etc. For a simpleminded db abstraction layer for
work. I can provide code shortly.
IMHO the database "abstraction toolkits" are all missing the point. In my
scripts, I want my variables. Now. It failed? Not the concern of the
script.
So far I've laid out 5 functions:
# returns the value of that column or NULL if it's NULL
$scalar = db_value("SELECT column FROM table WHERE unique_id=5"):
# returns an array of values of these columns
$list = db_list("SELECT column FROM table");
# returns a hash[column] = value
$row = db_row("SELECT * FROM table WHERE unique_id=5");
# returns a array of hashes
$rows = db_row("SELECT * FROM table");
# for sending updates, etc.
$result = db_send("UPDATE/INSERT/DELETE whatever");
All the guts of connections, interation, freeing results, etc. are hidden.
I've even implemented failover behind the scenes.
Error handling is ambiguous with respect to NULL values, so that gets a -1
until something exception-like appears in the language. (And I'm not in a
hurry for that.)
This has turned out to be really effective.
One thing which would also be amazing (also borrowed from some simple-DBI
thing) is to automatically map primary keys into hashes. So when fetching a
bunch of rows that have a primary key:
$rows = db_row("SELECT pkey, value FORM table", 'user_id');
# $rows['somepkey'] is then a reference to the value of that key
Get it?
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: A valuable addition to PHP...
2001-03-29 22:16 ` A valuable addition to PHP... Andrew Hammond <drew@waugh.econ.queensu.ca>
2001-03-30 03:17 ` Re: A valuable addition to PHP... Stephen van Egmond <svanegmond@bang.dhs.org>
@ 2001-03-31 21:16 ` Andrew Hammond <drew@waugh.econ.queensu.ca>
0 siblings, 0 replies; 5+ messages in thread
From: Andrew Hammond @ 2001-03-31 21:16 UTC (permalink / raw)
To: Stephen van Egmond <svanegmond@bang.dhs.org>; +Cc: pgsql-php
First off, I have to say that I'd never heard of PEAR before, but it looks
like a good database abstraction layer.
On Thu, Mar 29, 2001 at 10:17:44PM -0500, Stephen van Egmond wrote:
> On Thu, Mar 29, 2001 at 05:16:54PM -0500, Andrew Hammond wrote:
> > independant way of accessing metadata. Writing SQL queries that derive
> > metadata by futzing around with the pg_* tables works but is totally
> > non-portable. What I would really like to see is a database interface
> > layer that encapsulates all that nasty mess. Metadata and other
> > introspective stuff is a glaring ommission from SQL.
> IMHO the database "abstraction toolkits" are all missing the point.
You have definately missed my point. The key thing I'm interested in is
META data and introspective abilities. For example, I'm NOT talking about
selecting some data out of a table. I AM talking about getting a list of
databases in the dbm, tables/objects in the database, columns in the table.
That kind of thing. This is interesting because meta-data is exactly what
you need if you want to write meta-programming. Like, say, a generic web /
database interface...
> In my scripts, I want my variables. Now. It failed? Not the concern
> of the script.
How do you intend to deal with runtime error situations? Debugging?
Also, why didn't you use an object oriented approach so you could have
multiple connections to multiple databases?
Aside from those two rather serious issues, your api looks pretty good.
Personally, I'd rename the get_rows function to something like get_table.
get_rows is too close to get_row. I'd be apt to miss the s by accident
and spend a few hours doing blank stare debugging.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: A valuable addition to PHP...
2001-03-29 22:16 ` A valuable addition to PHP... Andrew Hammond <drew@waugh.econ.queensu.ca>
@ 2001-03-30 10:54 ` Jesus Aneiros <aneiros@ucfinfo.ucf.edu.cu>
1 sibling, 0 replies; 5+ messages in thread
From: Jesus Aneiros @ 2001-03-30 10:54 UTC (permalink / raw)
To: Andrew Hammond <drew@waugh.econ.queensu.ca>; +Cc: pgsql-php
Hi,
On Thu, 29 Mar 2001, Andrew Hammond wrote:
> non-portable. What I would really like to see is a database interface
> layer that encapsulates all that nasty mess. Metadata and other
> introspective stuff is a glaring ommission from SQL.
Could you develop this part a little bit more. I'm interested about it.
Best regards, Jesus.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: A valuable addition to PHP...
@ 2001-03-30 11:51 ` David Lizano <david.lizano@izanet.com>
1 sibling, 0 replies; 5+ messages in thread
From: David Lizano @ 2001-03-30 11:51 UTC (permalink / raw)
To: pgsql-php
>
>Of course yet-another-database-interface-layer while certainly a good
>and usefull piece of engineering wouldn't be particularly new and
>innovative. What _would_ be new and innovate, and maybe even impressive
>is a database interface layer that provides not just the usual database
>independant connect / query / result stuff but an organized, database
>independant way of accessing metadata. Writing SQL queries that derive
>metadata by futzing around with the pg_* tables works but is totally
>non-portable. What I would really like to see is a database interface
>layer that encapsulates all that nasty mess. Metadata and other
>introspective stuff is a glaring ommission from SQL.
You should see this pear tutorial. Pear have an abstraction layer library
for databases.
http://www.phpbuilder.com/columns/allan20010115.php3
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2001-03-31 21:16 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-03-29 22:16 ` Andrew Hammond <drew@waugh.econ.queensu.ca>
2001-03-30 03:17 ` Stephen van Egmond <svanegmond@bang.dhs.org>
2001-03-31 21:16 ` Andrew Hammond <drew@waugh.econ.queensu.ca>
2001-03-30 10:54 ` Jesus Aneiros <aneiros@ucfinfo.ucf.edu.cu>
2001-03-30 11:51 ` David Lizano <david.lizano@izanet.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