Generic database interface
| From: | Ragnar Kjørstad | Date: | Sat, 28 Oct 2000 02:58:11 +0000 |
| Subject: | Generic database interface | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-36239@lists.php.net to get a copy of this message | ||
Hi
We use php for accessing databases a lot, and see some shortcommings in
the interface. (we mostly use postgresql):
* The interface is postgresql specific - makes it hard to migrate
to/from other database systems.
* pg_exec returns postgres datastrucure instead of php datastructure
We would want to access the results of the queries directly by
looking up in php datastructures instead of having to use
functions to return the data
To overcome theese shortcommings, we use our own wrapper library for all
database access. However, we would like to see this functionality
implemented more generally.
A possible API:
Connections:
$conn=db_connect($dbms, $dbms_specific);
db_disconnect($conn);
db_setdefault($conn);
Standard query-form:
$res=sql_exec($query[, $conn]);
sql_clear($res);
$rows=sql_numrows($res);
$cols=sql_numcols($res);
$value=sql_value($res, $row, $col);
$col=sql_colbyname($col_name);
Simplified query-form:
$value=sql_singleExec($query[, $conn]);
// Fail if query returned multiple rows or multiple columns
// Return value of first column in first row.
$array=sql_horExec($query[, $conn]);
// Fail if query returned multiple rows
// Return array containing first row (indexed by field-names?) as array
$array=sql_verExec($query[, $conn]);
// Fail if query returned > 2 columns
// If 1 column: Return array with values
// If 2 columns: Return array with values from 2. column indexed by 1.
// column
$array=sql_fullExec($query[, $conn]);
// Return array of array containing all the result-data
All the simplified query-forms serves easier access to data of simple
queries, and not having to "clean up" using sql_clear afterwards.
Another possible interesting extention is supporting paralell databases:
* send write queries to multiple database servers
* send read queries to random database server
Now, to my questions:
* Are we the only ones that need/want this kind of interface, or is
it a general feature that others could benefit from?
* Is this the correct API? changes, additions, comments?
* How should it be implemented?
* Write a sql module on top of all the database modules in php
* Implement a more generic framework for database modules in php,
where each database module "registers" with a sentral database
module offering services.
* Implement the interface as a php-class, and make it
available seperately from php
Thanks.
--
Ragnar Kjørstad
Modus Media