Php connection to mysql database class (interface implementation)
This article introduces the php-implemented connection class to the mysql database. this class first defines an interface and then implements a specific method. For more information, see. The code for php and mysql connection classes is as follows:
Link (); * // interface definition 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 ();} /***** use a category to operate 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 publi C function connect () {$ this-> _ link = @ mysql_connect ('localhost', 'faizal', 'xxxxxxxxxxxxxx', '123 ') 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 ($ th Is-> _ 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 _ CloseMy SQL () {$ 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 Class Call example:
Conf_Show_Mysql(); // Set Variable Function $_Configure ->DB_Selected(); // Set Variable Function $_Configure ->_CloseMysql(); // Set Variable Function $_Configure ->Eroor_Show(); ?> |