php串連mysql資料庫的類(介面實現)

來源:互聯網
上載者:User
本文介紹下,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(); ?>
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.