Created abstract base database manip class
This commit is contained in:
parent
4182776c21
commit
377c319bd2
@ -24,6 +24,9 @@ abstract class DB_PDO extends PDO {
|
||||
function __construct($dsn, $username=NULL, $password=NULL, $driver_options=array())
|
||||
{
|
||||
parent::__construct($dsn, $username, $password, $driver_options);
|
||||
|
||||
$class = __CLASS__.'_manip';
|
||||
$this->manip = new $class;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
@ -135,4 +138,24 @@ abstract class DB_PDO extends PDO {
|
||||
*/
|
||||
abstract function num_rows();
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Abstract parent for database manipulation subclasses
|
||||
*/
|
||||
abstract class db_manip {
|
||||
|
||||
/**
|
||||
* Get database-specific sql to create a new table
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $columns
|
||||
* @param array $constraints
|
||||
* @param array $indexes
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract function create_table($name, $columns, $constraints, $indexes);
|
||||
}
|
||||
// End of db_pdo.php
|
@ -156,7 +156,21 @@ class firebird {
|
||||
*/
|
||||
function num_rows()
|
||||
{
|
||||
// TODO: Implement
|
||||
$count = 0;
|
||||
|
||||
if(isset($this->statement))
|
||||
{
|
||||
while($row = $this->fetch())
|
||||
{
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
}
|
||||
// End of firebird.php
|
@ -17,12 +17,7 @@
|
||||
*
|
||||
* PDO-firebird isn't stable, so this is a wrapper of the ibase_ functions.
|
||||
*/
|
||||
class firebird_manip extends firebird {
|
||||
|
||||
function __construct($db, $user="sysdba", $pass="masterkey")
|
||||
{
|
||||
parent::__construct($db, $user, $pass);
|
||||
}
|
||||
class firebird_manip extends db_manip{
|
||||
|
||||
function create_table($name, $fields, $constraints=array())
|
||||
{
|
||||
|
@ -15,11 +15,11 @@
|
||||
/**
|
||||
* MySQL Database manipulation class
|
||||
*/
|
||||
class MySQL_manip extends MySQL {
|
||||
class MySQL_manip extends db_manip{
|
||||
|
||||
function __construct($dsn, $user=null, $pass=null, $opt=array())
|
||||
function create_table($name, $columns, $constraints, $indexes)
|
||||
{
|
||||
parent::__construct($dsn, $user, $pass, $opt);
|
||||
//TODO: implement
|
||||
}
|
||||
}
|
||||
//End of mysqlL_manip.php
|
||||
//End of mysql_manip.php
|
@ -17,11 +17,12 @@
|
||||
*
|
||||
* @extends ODBC
|
||||
*/
|
||||
class ODBC_manip extends ODBC {
|
||||
class ODBC_manip extends db_manip {
|
||||
|
||||
function __construct($dsn, $username=null, $password=null, $options=array())
|
||||
function create_table()
|
||||
{
|
||||
parent::__construct("odbc:$dsn", $username, $password, $options);
|
||||
//ODBC can't know how to create a table
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
// End of odbc_manip.php
|
@ -17,11 +17,11 @@
|
||||
*
|
||||
* @extends PgSQL
|
||||
*/
|
||||
class pgSQL_manip extends pgSQL {
|
||||
class pgSQL_manip extends db_manip {
|
||||
|
||||
function __construct($dsn, $username=null, $password=null, $options=array())
|
||||
function create_table($name, $columns, $constraints, $indexes)
|
||||
{
|
||||
parent::__construct($dsn, $username, $password, $options);
|
||||
//TODO: implement
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,12 +15,7 @@
|
||||
/**
|
||||
* SQLite Database manipulation class
|
||||
*/
|
||||
class SQLite_manip extends SQLite {
|
||||
|
||||
function __construct($dsn)
|
||||
{
|
||||
parent::__construct($dsn);
|
||||
}
|
||||
class SQLite_manip extends db_manip {
|
||||
|
||||
/**
|
||||
* Convenience function to create a new table
|
||||
|
Loading…
Reference in New Issue
Block a user