Advertisement
Guest User

Untitled

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