Location: PHPKode > scripts > webstat > webstat/database.php
<?php

/*============================================================================================
                        This class is developed by Md. Mahabubur Rahman
                        For more information contact with me  [hide@address.com]
                        THANKS ALL FOR USING THIS CLASS
==============================================================================================*/



/* include constant file */
include('constant.php');

class MySql{
	
	/* Variable for Connection */
	var $connection;
	var $date;
	var $time;
	
	/*class constructor*/
	function MySql(){
		$this->date=date("Y-m-d");
		$this->time= date("H:i:s");
		$this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error());
        mysql_select_db(DB_NAME, $this->connection) or die(mysql_error());
      	}
	
	
    
   // Insert Visitor and return VISIT ID
  function InsertVisitor($webid,$js){
   	        $sql="INSERT INTO ".TBL_VISITORS." (website_id,date,time,javascript) VALUES('".$webid."','".$this->date."','".$this->time."','".$js."')";
   	        $sqlres=mysql_query($sql,$this->connection);
   	        if(!$sqlres)
   	        echo mysql_error();
   	        if($sqlres){
   	        	$sql_select= "SELECT * FROM ".TBL_VISITORS." WHERE website_id='".$webid."' AND date='".$this->date."' AND time='".$this->time."' AND javascript='".$js."'";
   	        	$sql_select_res=mysql_query($sql_select,$this->connection);
   	        	while ($Row=mysql_fetch_object($sql_select_res)) {
   	        		$Visitid= $Row->id;
   	        	}
   	        	if($Visitid!='') return  $Visitid;
   	        	else return false;
   	        }
   	        else return false;
   }
   
   
   
   
   
   function InsertCountry($visitid,$ip,$id){
   	if(is_long($ip))
    $IPL=$ip;
    else  $IPL=ip2long($ip);
    $query="SELECT * FROM ".TBL_IP2C." WHERE ('$IPL'>=`IpRangeFirst` AND '$IPL'<=`IpRangeLast`) LIMIT 1";
    $queryres=mysql_query($query,$this->connection);
    while ($row=mysql_fetch_assoc($queryres)){
    	$countrycode = $row["Country"];
    	$countryname = addslashes($row["name"]);
    	$continent   = $row["continent"];
    }
   	$sql="INSERT INTO ".TBL_IP." (visit_id,web_id,date,time,ip,countrycode,country,continent) VALUES('".$visitid."','".$id."','".$this->date."','".$this->time."','".$ip."','".$countrycode."','".$countryname."','".$continent."')";
   	$sqlres=mysql_query($sql,$this->connection);
   	if(!$sqlres){
   		echo $sql;
   		echo "<br/>";
   		echo mysql_error();
   	}
   	  	
   }
   
   function InsertCOLOR($visitid,$id,$color,$resulation){
   	$sql="INSERT INTO ".TBL_COLOR." (visit_id,web_id,date,time,color,resulation) VALUES('".$visitid."','".$id."','".$this->date."','".$this->time."','".$color."','".$resulation."') ";
    $sqlres=mysql_query($sql,$this->connection);
    if(!$sqlres){
    	echo $sql;
    	echo "<br/>";
    	
    }
   	
   }
   
   function InsertAdditionalDetail($visitid,$id,$os,$bro){
   	$sql="INSERT INTO ".TBL_DETAILS." (visit_id,web_id,date,time,operting_system,browser) VALUES('".$visitid."','".$id."','".$this->date."','".$this->time."','".$os."','".$bro."') ";
   	$sqlres=mysql_query($sql,$this->connection);
   }
   
   function InsertRefer($visitid,$webid,$referurl,$searchkey,$SearchEngine){
   	$sql="INSERT INTO ".TBL_URL." (visit_id,web_id,date,time,url,searchkey,searchengine) VALUES('".$visitid."','".$webid."','".$this->date."','".$this->time."','".$referurl."','".$searchkey."','".$SearchEngine."') ";
   	$sqlres=mysql_query($sql,$this->connection);
   }
   
   
   
}

$MySql= new MySql();

?>
Return current item: webstat