Hola, visita Hotscripts.com hay muchas clases de ese estilo.
Hace algún tiempo descargue una que sirve para mysql y acces, a pesar de que yo no la uso (pues programé una de acuerdo a mis necesidades) esta buenba para que veas como hacerla, sólo debes agregarle a esta clase las bases de datos que faltan o que te gustarían utilizar.
Código PHP:
<?php
/*
Since every database has differences with queries, the following set of standardizations
has been created to make the queries work without modification between database types
[ and ] encapsulate field and table names (Access SQL style)
\' escapes a single quote (MySQL style), no other \ escape sequences should be used
Example:
INSERT INTO [Table] ([Field]) VALUES('It\'s a value')
*/
// set to 1 to enable a flushed print of any query run, 0 disables
define("DEBUG", 0);
// the type of database to use:
define("ACCESS", 0);
define("MYSQL", 1);
class database {
var $type=-1;
var $conn='';
var $results=array();
var $index=array();
var $count=array();
/*
Constructor- establishes the database type and creates a connection
@param: $type- the database type: ACCESS, MYSQL
@param: $database- the database, for ACCESS, the path to the database file,
for MYSQL, the name of the database
@param: $host- MYSQL only, the host where the database resides
@param: $username- MYSQL only, the username for the database user
@param: $password- MYSQL only, the password for username
*/
function database($type, $database, $host='', $username='', $password='') {
$this->type=$type;
switch($this->type) {
case ACCESS:
$this->conn=new COM('ADODB.Connection');
$this->conn->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={$database};Mode=ReadWrite;");
break;
case MYSQL:
$this->conn=@mysql_connect($host,$username,$password);
@mysql_select_db($database, $this->conn);
break;
}
}
/*
Query- runs a query on the database connection and saves the results for extraction
@param: $sql- the SQL string
@param: $key- an identifier to store the results
*/
function query($sql, $key=0) {
$sql=$this->parse($sql);
$this->debug($sql);
switch($this->type) {
case ACCESS:
$this->results[$key]=$this->conn->Execute($sql);
$this->count[$key]=$this->results[$key]->RecordCount();
break;
case MYSQL:
$this->results[$key]=@mysql_query($sql, $this->conn);
$this->count[$key]=@mysql_num_rows($this->results[$key], $this->conn);
break;
}
$this->index[$key]=0;
}
/*
Execute- runs a query on the database connection but does not save results,
used for queries of type INSERT, UPDATE, etc.
@param: $sql- the SQL string
*/
function execute($sql) {
$sql=$this->parse($sql);
$this->debug($sql);
switch($this->type) {
case ACCESS:
$this->conn->Execute($sql);
break;
case MYSQL:
@mysql_query($sql, $this->conn);
break;
}
}
/*
Next- moves to the next record in the results
@param: $key- an identifier to a stored results resource
*/
function next($key=0) {
switch($this->type) {
case ACCESS:
if(!$this->results[$key]->EOF())
$this->results[$key]->MoveNext();
break;
case MYSQL:
if($this->index[$key]<$this->count[$key])
$this->index[$key]++;
break;
}
}
/*
Move- moves a specified number of records in the results, or last record
@param: $count- the nmber of records to move at maximum
@param: $key- an identifier to a stored results resource
*/
function move($count, $key=0) {
switch($this->type) {
case ACCESS:
$this->results[$key]->Move($count);
break;
case MYSQL:
$this->index[$key]=min(array($this->count[$key]-1, $this->index[$key]+$count));
break;
}
}
/*
Result- returns the value from the specified field of the current record
@param: $field- the field name of the desired result
@param: $key- an identifier to a stored results resource
*/
function result($field, $key=0) {
switch($this->type) {
case ACCESS:
return $this->results[$key]->Fields[$field]->Value;
break;
case MYSQL:
return @mysql_result($this->results[$key], $this->index[$key], $field);
break;
}
}
/*
EOF- returns true if end of file is reached for the current result resource
@param: $key- an identifier to a stored results resource
*/
function eof($key=0) {
switch($this->type) {
case ACCESS:
return $this->results[$key]->EOF();
break;
case MYSQL:
return ($this->index[$key]>=$this->count[$key]);
break;
}
}
/*
Clear- clears the result resources
@param: $key- an identifier to the results resource to be cleared
*/
function clear($key=0) {
unset($this->results[$key], $this->index[$key], $this->count[$key]);
}
/*
Close- closes the database connection
*/
function close() {
switch($this->type){
case ACCESS:
$this->conn->Close();
break;
case MYSQL:
@mysql_close($this->conn);
break;
}
unset($this->results, $this->conn);
}
/*
(private) Parse- modifies the SQL statement to translate from the standard query
syntax to the specific database syntax
@param: $sql- the SQL string to parse
@return: the parsed SQL string
*/
function parse($sql) {
switch($this->type) {
case ACCESS:
$sql=str_replace("\'", "''", $sql);
break;
case MYSQL:
$sql=str_replace("[", "`", str_replace("]", "`", $sql));
break;
}
return $sql;
}
/*
(private) Debug- prints a debug message to the screen when enabled
@param: $debug- the debug message to print
*/
function debug($debug) {
if(DEBUG) {
echo $debug;
flush();
ob_flush();
}
}
} // end database class
?>