kranthi wrote:
thanks for the comments,
what i m planning to do is....
function _autoload($class) {
if($class == 'Database') {
if(class_exis('PDO') {
include_once('Database_PDO.php');
} else {
include_once('Database.php');
}
}
where in Database_PDO.php contains
class Database extends PDO {
}
Database.php contains
class Database {
}
appears to me it should be:
abstract class Database {
class PDODatabase extends Database {
class MysqlDatabase extends Database {
...etc
because if you don't have PDO how can you extend it...? ;)
then
class Persistence {
private static $database;
public function select( $sql )
{
self::getDatabase()->query( $sql );
}
public static function getDatabase()
{
if( !(self::$database instanceof Database) ) {
if( class_exists( 'PDODatabase' ) ) {
self::$database = new PDODatabase();
} elseif( function_exists('mysql_query') ) {
self::$database = new MysqlDatabase();
}
}
return self::$database;
}
}
or suchlike
one thing you will need to consider is getting database connection
settings in there for instantiation; in which case injecting a
configured instance of the required database handler in to the
persistence layer may be more suitable.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php