Advertisement
Guest User

Untitled

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