Jump to content
php.lv forumi

Redzēt visus mysql querijus


loyd

Recommended Posts

Vienkāršā variantā daram aptuveni šādi:

<?php

class db extends mysqli
{
private static $instance;
private function __construct()
{
	parent::__construct(DB_HOST,DB_LOGIN,DB_PASS, DB_DB);
	$this->set_charset("utf8");	
}  

//================ PUBLIC =====================
// get Instance of db singleton
public static function I()
{
	if (!self::$instance instanceof self)
	{ 
		self::$instance = new self;			
	}
	return self::$instance;
}	


public function dbQuery($query)
{
	var $start_time = microtime();
	$result = self::query($query) or die(self::I()->error);
	var $end_time = microtime();
	self::logquery($query,$end_time-$start_time,$result);		
	return $result;  
}
public function logquery($query,$time,$result){
	//šeit logojam kā un ko gribam.
}

}

 

Izmantojam:

db::I()->dbQuery('SELECT 1');

Edited by codez
Link to comment
Share on other sites

diezvai ir sapratigi katru vaicajumu veidot ka jaunu objektu

 

labak klase nodefinet mainigo, kas skaita cik reizes query ir izpildits un, attieciga vieta izsaukt to metodi, kas atgriez sho attributu.

 

class cntTest{
private $qCnt;

 public function fakeQuery(){
$this->qCnt++;
//make query
 }

 public function getCnt(){
  return $this->qCnt;
 }

}


$x = new cntTest();
$x -> fakeQuery();
$x -> fakeQuery();
$x -> fakeQuery();
echo $x -> getCnt(); //3

Link to comment
Share on other sites

tad metodi vajadzetu bik pielabot

 

  public function fakeQuery($qeury){
$this->qCnt[] = $qeury;
//make query
 }

Link to comment
Share on other sites

Lai varetu veikt dazadus logus, manis pec, var f-ju vai vienkarshi masiva ierakstit pirms izsaukt vaicajumu.

Link to comment
Share on other sites

×
×
  • Create New...