Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class database{
- public $server = "";
- public $user = "";
- protected $dbName;
- protected $password = "";
- public $error = array();
- protected $conn;
- public function __construct($server, $user, $password, $databaseName){ // change this later to be more efficient
- // check if the server is set
- if($server == "")
- {
- $this->error[] = "server is empty";
- }
- // check if the password is set
- if($user == "")
- {
- $this->error[] = "user is empty";
- }
- // check if the server is set
- if($password == "")
- {
- $this->error[] = "password is empty";
- }
- // check if the password is set
- if($databaseName == "")
- {
- $this->error[] = "databaseName is empty";
- }
- $this->server = $server;
- $this->user = $user;
- $this->password = $password;
- $this->dbName = $databaseName;
- }
- function conn(){ // create a connection with the database
- $conn = mysqli_connect($this->server, $this->user, $this->password, $this->dbName);// database connection
- return $conn;
- }
- function select($colum, $table){ //a select function to make it easy to select rows from the database
- $this->conn = $this->conn(); // make a new connection
- //maak verbinding
- //SELECT name FROM landen
- $sql = "SELECT ".$colum." FROM ". $table; //make a string containing the sql
- $query = mysqli_query($this->conn, $sql); //execute the sql
- mysqli_close($this->conn); // cloe the connection.
- //this makes it harder for people to intercept the communication between the server and the client(this includes scripts and such)
- return $query; // return the result to the place where you execute it
- }
- function selectWhere($colum, $table, $where){
- $this->conn = $this->conn();
- // SELECT name FROM landen WHERE landID=3
- $sql = "SELECT ".$colum." FROM ".$table." WHERE ".$where;
- $query = mysqli_query($this->conn, $sql);
- mysqli_close($this->conn);
- return $query;
- }
- function insert($table, $colums,$values){ /// NOT DONE CHANGE THE CONNS TO $THIS YOU DIP
- $this->conn = conn();
- // INSERT INTO landen (name) VALUES (Duitsland)
- $sql = "INSERT INTO ".$table." (".$colums.") VALUES (".$values.")";
- // INTERT INTO producten (type,bouwjaar,prijs,image)
- // VALUES ("A4")
- mysqli_query($conn, $sql);
- $lastID = mysqli_insert_id($conn); // EXTRA VOOR DEZE OPDRACHT
- mysqli_close($conn);
- return $lastID;
- }
- // make a function to insert an array into the database. work on this in the near futer
- /* function insertArray($array, $table)
- {
- $this->conn = conn();
- foreach($array)
- // INSERT INTO landen (name) VALUES (Duitsland)
- $sql = "INSERT INTO ".$table." (".$colums.") VALUES (".$values.")";
- // INTERT INTO producten (type,bouwjaar,prijs,image)
- // VALUES ("A4")
- mysqli_query($conn, $sql);
- $lastID = mysqli_insert_id($conn); // EXTRA VOOR DEZE OPDRACHT
- mysqli_close($conn);
- return $lastID;
- }*/
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement