<?php class databse { var $host="localhost"; var $username="root"; var $password=""; var $database="testdb"; var $prefix=""; public $con; function __construct($host = NULL, $username = NULL, $password = NULL, $database = NULL, $prefix = NULL) { $this->hostname = ! empty ( $host ) ? $host : $this->host; $this->username = ! empty ( $username ) ? $username : $this->username; $this->password = ! empty ( $password ) ? $password : $this->password; $this->database = ! empty ( $database ) ? $database : $this->database; $this->prefix = ! empty ( $prefix ) ? $prefix : $this->prefix; $this->con = mysqli_connect ( $this->host, $this->username, $this->password, $this->database ) or die ( 'Error connecting to DB' ); } public function query($sql) { return mysqli_query($this->con, $sql) or die ( 'Error:' . mysqli_error ( $this->con ) . ', query: ' . $sql ); } public function fetch($sql) { $array = mysqli_fetch_array ( $this->query ( $sql ) ); return $array; } public function insert($data, $table) { mysqli_query( $this->con,"INSERT INTO ".$table." (".$fields.") VALUES (".$vals.")"); } public function update($data, $table) { mysqli_query($this->con,"UPDATE ".$table." SET age=36 WHERE id=1"); } public function delete($data, $table) { mysqli_query($this->con,"DELETE FROM ".$table." WHERE age=36"); } public function close() { return mysqli_close ( $this->con ); } function __destruct() { $this->close (); } } $db=new databse(); ?>