mysql php 接口_php连接mysql数据库的类(接口实现)

本文介绍下,php实现的连接mysql数据库的类,本类先定义一个接口,然后再实现具体方法。有需要的朋友参考下吧。

php与mysql连接类的代码分享,如下:

Link ();

*/

//接口定义

interface Connected

{

// Buat Bayangan Pertama

public function __construct();

// Buat Bayangan Function Kedua

public function connect ();

// Buat Bayangan Function Ketiga

public function error_mysql ();

// Buat Bayangan Function Keempat

public function db_selected ();

// Buat Bayangan Function Kelima

public function mysql_close ();

}

/**

*

* 使用接品类操作mysql

*

* @return Function Dari Interface

* @var String Variable

*/

class ConfigureMysql implements Connected{

/**

* @var String

*/

var $_link ;

/**

* @var String

*/

var $_Link_Cons ;

/**

* @var String

*/

var $_Error;

/**

* @var String

*/

var $_DB;

// Setting Function Dari Interface

public function __construct() {

$this ->_Link_Cons = $this ->connect();

return $this ->_Link_Cons ;

}

// Setting Function Kedua Dari Interface

public function connect () {

$this ->_link = @mysql_connect('localhost' , 'Faizal' , 'XXXXXXXXXXX' , '3306') or die($this->error_mysql ());

}

// Settiong Function Ketiga Dari Interface

public function error_mysql () {

$this ->_Error = "

Masalah Pada Koneksi Ke Jalur Mysql";

}

// Settiong Function Keempat Dari Interface

public function db_selected () {

$this ->_DB = mysql_select_db('XXXXXXXX');

if ($this ->_DB != TRUE) {

return $this ->error_mysql();

}else {

return false ;

}

}

// Setting Function Kelima Dari Interface

public function mysql_close () {

return mysql_close($this ->connect());

}

}

/**

* Gunakan Script Classes Untuk Function Parent::

*

* @example parent::__Construct();

*/

class LinkCon extends ConfigureMysql {

/**

* @var String

*/

var $_Con ;

/**

* @var String

*/

var $_Db ;

/**

* @magic Self::

*/

var $_Error_Show ;

/**

* @return Mysql_Close

*/

var $_Close ;

// Setting Function Dari Class Yang Di Extends

public function Conf_Show_Mysql () {

$this ->_Con = parent::__construct();

}

// Setting Function Dari Class Yang Di Extends

public function DB_Selected () {

$this ->_Db = $this ->DB_Selected();

return $this ->_Db ;

}

// Setting Function Dari Class Yang Di Extends

public function _CloseMysql () {

$this ->_Close = $this ->mysql_close();

return $this ->_Close ;

}

// Set Error

public function Eroor_Show () {

$this ->_Error_Show = $this ->error_mysql();;

return true ;

}

// Akhir Classes

}

?>

2,mysql类的调用示例:

Conf_Show_Mysql();

// Set Variable Function

$_Configure ->DB_Selected();

// Set Variable Function

$_Configure ->_CloseMysql();

// Set Variable Function

$_Configure ->Eroor_Show();

?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值