PHP connection to MySQL database Class (interface implementation)

Source: Internet
Author: User
Tags php and mysql
This article describes the PHP implementation of a connection to the MySQL database class, this class first define an interface, and then implement the concrete method. Please refer to the friends who are in need.

The code share 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 (); }/** * * Using the category operation MySQL * * @return Function Dari Interface * @var String Variable */class Configuremysql Impleme  NTS 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 (' XXXXXX XX '); 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_select Ed (); 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}?>
Example invocation of the 2,mysql class:
 
      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.