Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class DB
- {
- /**
- * Set the properties
- */
- public $host;
- public $username;
- public $password;
- public $database;
- private $connection;
- public function setHost($host)
- {
- $this->host = $host;
- }
- public function getHost()
- {
- return $this->host;
- }
- public function setUsername($username)
- {
- $this->username = $username;
- }
- public function getUsername()
- {
- return $this->username;
- }
- public function setPassword($password)
- {
- $this->password = $password;
- }
- public function getPassword()
- {
- return $this->password;
- }
- public function setDatabase($database)
- {
- $this->database = $database;
- }
- public function getDatabase()
- {
- return $this->database;
- }
- /**
- * Generate an error for the whole class
- */
- public function error($title, $message)
- {
- $output = '<div style="margin: 0; padding: 0; border: 2px solid #990000; color: #990000;">
- <div style="font-size: 14px; font-family: Calibri, Arial, Helvetica, sans-serif; font-weight: bold;">' . $title . '</div>
- <div style="font-size: 12px; font-family: Calibri, Arial, Helvetica, sans-serif; font-weight: normal;">' . $message . '</div>
- </div>';
- return $output;
- }
- /**
- * Make a connection to the database
- */
- public function connect()
- {
- if(!$this->connection = mysqli_connect(getHost(), getUsername(), getPassword(), getDatabase())
- {
- error(
- 'Kon niet verbinden met de database!',
- 'Host: ' . getHost() . '<br />
- Gebruikersnaam: ' . getUsername() . '<br />
- Wachtwoord: ********<br />
- Database: ' . getDatabase() . '<br />
- Error: ' . mysqli_error . ''
- );
- }
- else
- {
- if(!mysqli_select_db($this->connection, getDatabase())
- {
- error(
- 'Verkeerde database geselecteerd!',
- 'Host: ' . getHost() . '<br />
- Gebruikersnaam: ' . getUsername() . '<br />
- Wachtwoord: ********<br />
- Database: ' . getDatabase() . '<br />
- Error: ' . mysqli_error() . ''
- );
- }
- }
- }
- }
- ?>
Add Comment
Please, Sign In to add comment