Advertisement
Guest User

Untitled

a guest
May 9th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.02 KB | None | 0 0
  1. <?php
  2.  
  3. /***
  4. *
  5. * Class: mysql
  6. * Usage: $mysql = new mysql('host', 'gebruikersnaam', 'wachtwoord', 'database');
  7. * Author: Chris Horeweg, based on Lode's Class
  8. * Year: 2008
  9. *
  10. **/
  11.  
  12. class mysql
  13. {
  14.     protected $connection = NULL;
  15.  
  16.     # De construct laat zien welke waarden je bij een nieuwe class moet meegeven,
  17.    # en wat er wordt gedaan als de class wordt aangeroepen.
  18.    public function __construct($host=NULL, $user=NULL, $password=NULL, $database=NULL)
  19.     {
  20.         if(isset($host))
  21.         {
  22.             $this->connect($host, $user, $password);
  23.             if(isset($database))
  24.             {
  25.                 $this->select_database($database);
  26.             }
  27.         }
  28.     }
  29.  
  30.     # Verbinding maken met de host
  31.    public function connect($host=NULL, $user=NULL, $password=NULL)
  32.     {
  33.         if(!$this->link = @mysql_connect($host, $user, $password))
  34.         {
  35.             throw new mysql_exception;
  36.         }
  37.     }
  38.  
  39.     # Verbinding maken met de database
  40.    public function select_database($database)
  41.     {
  42.         if($this->connected())
  43.         {
  44.             if(!@mysql_select_db($database, $this->connection))
  45.             {
  46.                 throw new mysql_exception;
  47.             }
  48.         }
  49.         else
  50.         {
  51.             throw new Exception('No database connection..');
  52.         }
  53.     }
  54.  
  55.     # Een query uitvoeren
  56.    public function query($sql)
  57.     {
  58.         $result = @mysql_query($sql);
  59.         if($result)
  60.         {
  61.             return $result;
  62.         }
  63.         throw new mysql_exception;
  64.     }
  65.  
  66.     # mysql_real_escape_string(); over een waarde heen gooien
  67.    public function escape($string)
  68.     {
  69.         if($this->connected())
  70.         {
  71.             return @mysql_real_escape_string(sprintf('%s', $string), $this->connection);
  72.         }
  73.         else
  74.         {
  75.             throw new mysql_exception;
  76.         }
  77.     }
  78.  
  79.     # Is er een verbinding met een MySQL database?
  80.    public function connected()
  81.     {
  82.         return @mysql_ping($this->connection);
  83.     }
  84. }
  85. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement