Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Database implements DataSource
- {
- private $link;
- private $host;
- private $user;
- private $pass;
- private $result;
- //Foutmelding die in meerdere functies gebruikt wordt
- private $noresult = "Er is geen resultset, voer eerst een query uit!";
- //Constructor met de vereiste parameters
- public function Database($host, $user, $pass, $database)
- {
- if($host && $user)
- {
- $this->host = $host;
- $this->user = $user;
- $this->pass = $pass;
- $this->Connect();
- if(!mysql_select_db($database, $this->link))
- throw new Exception("Kan de database " . $database . " niet selecteren");
- }
- mysql_set_charset("utf8", $this->link);
- }
- //Connectie naar de mysql database leggen
- private function Connect()
- {
- $this->link = mysql_connect($this->host, $this->user, $this->pass, true);
- if(!$this->link)
- {
- throw new Exception("Kan geen connectie met de database maken.");
- }
- }
- //Query functie uitvoeren en een fout geven als het fout gaat
- public function Query($query = "")
- {
- if($query != "")
- {
- $this->result = mysql_query($query, $this->link);
- }
- else
- {
- throw new Exception("De query is leeg!");
- }
- if(!$this->result)
- {
- throw new Exception( "Fout tijdens query: ($query)");
- }
- return $this->result;
- }
- public function Fetch_Object($objecttype=null, $result=NULL)
- {
- if(!$result)
- {
- $result = $this->result;
- }
- if($result)
- {
- if(is_null($objecttype))
- return mysql_fetch_object($result);
- else
- return mysql_fetch_object($result, $objecttype);
- }
- else
- {
- throw new Exception($this->noresult);
- }
- }
- //Fetch_Assoc functie van mysql zodat je $row["naam"] kunt gebruiken
- public function Fetch_Assoc($result=NULL)
- {
- if(!$result)
- {
- $result = $this->result;
- }
- if($result)
- {
- return mysql_fetch_assoc($result);
- }
- else
- {
- throw new Exception($this->noresult);
- }
- }
- //Fetch_Array functie van mysql zodat je $row[0] kunt gebruiken
- public function Fetch_Array()
- {
- if($this->result)
- {
- return mysql_fetch_array($this->result);
- }
- else
- {
- throw new Exception($this->noresult);
- }
- }
- //Fetch row functie van mysql voor het ophalen van 1 rij
- public function Fetch_Row()
- {
- if($this->result)
- {
- return mysql_fetch_row($this->result);
- }
- else
- {
- throw new Exception($this->noresult);
- }
- }
- public function Mysql_Batch_Query($query)
- {
- $this->querys[] = "Batchquery ". $query;
- $batch_connection = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
- $batch_connection->multi_query($query);
- $batch_connection->close();
- }
- //Deze functie geeft het laatst toegevoegde id terug
- public function GetLastid()
- {
- return mysql_insert_id($this->link);
- }
- //Deze functie geeft het aantal geraakte rijen van de laatste query terug
- public function Nuw_Rows()
- {
- if($this->result)
- {
- return mysql_num_rows($this->result);
- }
- else
- {
- throw new Exception($this->noresult);
- }
- }
- public function Affected_Rows()
- {
- return mysql_affected_rows();
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement