From: Stephen van Egmond <svanegmond@bang.dhs.org>
To: Andrew Hammond <drew@waugh.econ.queensu.ca>
Cc: PostgreSQL-PHP list <pgsql-php@postgresql.org>
Subject: Re: A valuable addition to PHP...
Date: Thu, 29 Mar 2001 22:17:44 -0500
Message-ID: <20010329221744.A6990@bang.dhs.org> (raw)
In-Reply-To: <20010329171654.A12635@waugh.econ.queensu.ca>
References: <3ABFADEE.6000802@greatbridge.com>
<20010329171654.A12635@waugh.econ.queensu.ca>
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?
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-php@postgresql.org
Cc: svanegmond@bang.dhs.org, drew@waugh.econ.queensu.ca
Subject: Re: A valuable addition to PHP...
In-Reply-To: <20010329221744.A6990@bang.dhs.org>
References: <3ABFADEE.6000802@greatbridge.com> <20010329171654.A12635@waugh.econ.queensu.ca> <20010329221744.A6990@bang.dhs.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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