Código PHP:
class DAC
{
var $db;
function &create( $name, $dac_type="mysql" )
{
if ($dac_type == "mysql") {
switch ( $name )
{
case "news" : return new MySQLNews(); break;
case "users" : return new MySQLUsers(); break;
case "admins" : return new MySQLAdmins(); break;
......
......
default : return null; break;
}
}
if ($dac_type == "ws") {
switch ( $name )
{
case "news" : return new WSNews(); break;
case "users" : return new WSUsers(); break;
case "admins" : return new WSAdmins(); break;
.....
.....
default : return null; break;
}
}
}
}
class MySQLNews extends MySQLDAC //implements IDACNews
{
function create( $news )
{
$sql = sprintf( "INSERT INTO news ( 0, %s )", $news );
return $this->db->execute_non_query ( $sql, true ); }
function read( $id )
{
$sql = "SELECT * FROM news WHERE news_id = %s";
return $this->db->execute_query( sprintf( $sql, $id ) );
}
function get_all_news() {
$sql = "SELECT * from news";
return $this->db->execute_reader( sprintf( $sql ) );
}
function delete( $id )
{
$sql = "DELETE FROM news WHERE news_id = %s";
$this->db->execute_non_query( sprintf( $sql, $id ) );
}
function MySQLNews(){ parent::MySQLDAC(); }
}