标签:host 适配 将不 pdo base php function ase ace
<?php
//适配器模式
//将不同的函数封装成统一的api
//例如 将mysql pdo mysqli 一致
//接口
interface DataBase
{
function connect($host, $user, $password, $dbname);
}
class Mysql implements DataBase
{
public function connect($host, $user, $password, $dbname)
{
echo __CLASS__.‘ connect‘;
}
}
class MysqlPdo
{
public function connect($host, $user, $password, $dbname)
{
echo __CLASS__.‘ connect‘;
}
}
class MysqlMysqli
{
public function connect($host, $user, $password, $dbname)
{
echo __CLASS__.‘ connect‘;
}
}
$db = new Mysql();
$db->connect();
$db = new MysqlPdo();
$db->connect();
$db = new MysqlMysqli();
$db->connect();
标签:host 适配 将不 pdo base php function ase ace
原文地址:http://www.cnblogs.com/mingqinz/p/7003521.html