Advertisement
Guest User

Untitled

a guest
Jun 11th, 2012
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.74 KB | None | 0 0
  1. <?php
  2. interface Connection_Interface
  3. {
  4.   public function __construct($hostname, $username, $pass, $database, $table, $connector);
  5.   public function openConnect();
  6.   public function pingServer();
  7.   public function closeConnect();
  8.   public function startQuery($runQuery);
  9.   public function getResults();
  10. }
  11.  
  12. class databaseConnectMySql extends databaseConfig implements Connection_Interface
  13. {
  14.     /**
  15.      * declareren van alle functies
  16.      */
  17.     public $hostname;
  18.     public $username;
  19.     public $pass;
  20.     public $database;
  21.     public $table;
  22.     public $connector;
  23.  
  24.     public function __construct($hostname, $username, $pass, $database, $table, $connector)
  25.     {
  26.        
  27.     }
  28.  
  29.     public function __destruct()
  30.     {
  31.         #destroy function
  32.     }
  33.  
  34.     // open connectie
  35.     public function openConnect()
  36.     {
  37.         try
  38.         {
  39.                 $this->openConnect = mysql_connect($this->hostname, $this->username, $this->pass);
  40.                 $this->databaseConnect = mysql_select_db($this->database); 
  41.         }
  42.         catch (Exception $e)
  43.         {
  44.             return $e;
  45.         }
  46.        
  47.     }
  48.  
  49.     #run een query
  50.     public function startQuery($runQuery)
  51.     {
  52.         try
  53.         {
  54.             if(empty($this->openConnect))
  55.             {
  56.                 $this->openConnect();
  57.  
  58.                     $this->startQuery = mysql_query($query);
  59.  
  60.                 $this->closeConnect();
  61.                 return $this->startQuery;
  62.             }  
  63.             else
  64.             {
  65.                
  66.                     $this->startQuery = mysql_query($query);
  67.  
  68.                 return $this->startQuery;
  69.             }
  70.         }
  71.         catch (Exception $e)
  72.         {
  73.             return $e; 
  74.         }
  75.     }
  76.  
  77.     #sluit connectie
  78.     public function closeConnect()
  79.     {
  80.         try {
  81.                 mysql_close($this->openConnect);
  82.         }
  83.         catch (Exception $e)
  84.         {
  85.             return $e;
  86.         }
  87.     }
  88.  
  89.     /*
  90.     * ping server om te zien of deze open verbinding heeft.
  91.     */
  92.     public function pingServer()
  93.     {
  94.         # code...
  95.         try
  96.         {
  97.            
  98.                 if(!mysql_ping($this->openConnect))
  99.                 {
  100.                     return false;
  101.                 }
  102.                 else
  103.                 {
  104.                     return true;
  105.                 }
  106.            
  107.         }
  108.         catch (Exception $e)
  109.         {
  110.             return $e;
  111.         }
  112.     }
  113.  
  114.     public function getResults()
  115.     {
  116.         try
  117.         {
  118.                 return mysql_fetch_assoc($result);
  119.         }
  120.         catch (Exception $e)
  121.         {
  122.             return $e; 
  123.         }
  124.     }
  125. }
  126.  
  127. abstract class databaseConfig
  128. {
  129.     private $hostname;
  130.     private $username;
  131.     private $pass;
  132.     private $database;
  133.     private $table;
  134.     private $connector;
  135.  
  136.     function __construct($hostname = NULL, $username = NULL, $pass = NULL, $database = NULL, $prefix = NULL, $connector = NULL)
  137.     {
  138.         $this->hostname = !empty($hostname) ? $hostname : "";
  139.         $this->username = !empty($username) ? $username : "";
  140.         $this->pass = !empty($pass) ? $pass : "";
  141.         $this->database = !empty($database) ? $database : "";
  142.         $this->table = !empty($table) ? $table : "";
  143.         $this->connector = !empty($connector) ? $connector : "";  //mysql of mysqli waarde opgeven (database)
  144.     }
  145.  
  146.     function __destruct()
  147.     {
  148.         #destruction!
  149.     }
  150. }
  151. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement