Php connection to mysql database class (interface implementation)

Source: Internet
Author: User
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(); ?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.