Location: PHPKode > scripts > MySQLi sample test > mysqli-sample-test/db.inc.php
<?php
/***********************
Author: Sarmad mahar
Email:  hide@address.com , hide@address.com , hide@address.com
Description: This class is developed to use mysqli class
Features:

- Implementation of mysqli class 
- Sent email to admin if any query goes wrong without knowing vistors 
- Track querry errors 

**************/

class db{
	
var $link;
var $host="localhost";
var $user="root";
var $pass="";
var $db="DATA_BASE_NAME";
var $adminEmail="hide@address.com";

/******
change Value from 0 to 1 if you want to send email if any query goes wrong
**********/
var $is_SendEmail=0;
	

############### Class contructor ################################
	function __construct(){
		$this->link = mysqli_connect($this->host, $this->user, $this->pass, $this->db);
	/* check connection */
	if (!$this->link) {
		printf("Connect failed: %s\n", mysqli_connect_error());
		exit();
	}
	return $this->link;

	}

	
	function __destruct(){
		mysqli_close($this->link);
		
		}

	
################### Execute query #################################	
	function Executequery($query){

		$result = $this->link->query($query); 
		if (!$result) {
		$message  = 'Invalid query: ' . mysql_error() . "<br>";
		$message .= 'Whole query: ' . $query. "<br>";
		$message .= 'File Name: ' . $_SERVER['PHP_SELF']. "<br>";
		$message .= 'Date: ' . date("d/M/Y"). "<br>";
			if($this->is_SendEmail){
			$headers = 'From: '.$this->adminEmail . "\n" . 'Reply-To: '. $this->adminEmail . "\n" .'X-Mailer: PHP/' . phpversion();
			mail($this->adminEmail, 'Error in query', $message,$headers);
			}
			else{
			die($message);
			}
		}
		else {
		return $result;
		}
		
		}

	
}
?>
Return current item: MySQLi sample test