Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /***
- *
- * Class: mysql
- * Usage: $mysql = new mysql('host', 'gebruikersnaam', 'wachtwoord', 'database');
- * Author: Chris Horeweg, based on Lode's Class
- * Year: 2008
- *
- **/
- class mysql
- {
- protected $connection = NULL;
- # De construct laat zien welke waarden je bij een nieuwe class moet meegeven,
- # en wat er wordt gedaan als de class wordt aangeroepen.
- public function __construct($host=NULL, $user=NULL, $password=NULL, $database=NULL)
- {
- if(isset($host))
- {
- $this->connect($host, $user, $password);
- if(isset($database))
- {
- $this->select_database($database);
- }
- }
- }
- # Verbinding maken met de host
- public function connect($host=NULL, $user=NULL, $password=NULL)
- {
- if(!$this->link = @mysql_connect($host, $user, $password))
- {
- throw new mysql_exception;
- }
- }
- # Verbinding maken met de database
- public function select_database($database)
- {
- if($this->connected())
- {
- if(!@mysql_select_db($database, $this->connection))
- {
- throw new mysql_exception;
- }
- }
- else
- {
- throw new Exception('No database connection..');
- }
- }
- # Een query uitvoeren
- public function query($sql)
- {
- $result = @mysql_query($sql);
- if($result)
- {
- return $result;
- }
- throw new mysql_exception;
- }
- # mysql_real_escape_string(); over een waarde heen gooien
- public function escape($string)
- {
- if($this->connected())
- {
- return @mysql_real_escape_string(sprintf('%s', $string), $this->connection);
- }
- else
- {
- throw new mysql_exception;
- }
- }
- # Is er een verbinding met een MySQL database?
- public function connected()
- {
- return @mysql_ping($this->connection);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement