Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- interface idb
- {
- public function connect ( );
- public function fetch_assoc ( );
- public function query ( $sql );
- }
- abstract class adb implements idb
- {
- protected $db_host = null;
- protected $db_user = null;
- protected $db_pass = null;
- protected $db_name = null;
- protected $db_link = null;
- public function __construct ( $db_host, $db_user, $db_pass, $db_name )
- {
- $this->db_host = $db_host;
- $this->db_user = $db_user;
- $this->db_pass = $db_pass;
- $this->db_name = $db_name;
- $this->connect( );
- }
- }
- class db
- {
- protected $db = null;
- public function __construct ( $db_type, $db_host, $db_user, $db_pass, $db_name )
- {
- $this->db = new $db_type( $db_host, $db_user, $db_pass, $db_name );
- }
- }
- class MYSQL extends adb
- {
- public function connect ( )
- {
- mysql_connect( $this->db_host, $this->db_user, $this->db_pass );
- mysql_select_db( $this->db_name );
- }
- public function fetch_assoc ( )
- {
- return mysql_fetch_assoc( $this->db_link );
- }
- public function query ( $sql )
- {
- mysql_query( $sql, $this->db_link );
- }
- }
- // Usage
- $db = new db( 'MYSQL', 'localhost', 'root', '', 'localhost' );
- $db->query( 'SELECT * FROM table' );
- $result = $db->fetch_assoc( );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement