<?php
function microtime_float () {
return (float)$msec + (float)$sec;
}
class SQL {
//**Vars**\\
var $tijd;
var $connectie;
var $querys = 0;
var $fetchs = 0;
var $assocs = 0;
var $arrays = 0;
var $objects = 0;
var $numrows = 0;
//**Function Connect**\\
function connect($host="localhost", $username="", $password="", $database="") {
$microtime_start = microtime_float(); // Start Time
if(empty($host)) { // Empty Hostname die($this->_error
("Please fill in a host!")); } elseif(empty($database)) { // Empty Database die($this->_error
("Please fill in a database!")); } else {
if(mysql_connect($host, $username, $password)) { // Connection DB $this->connectie = "Geconnecteerd met ".$host; //
} else { // False
$this->connectie = "Connectie mislukt met ".$host;
}
$this->connectie = "Geconnecteerd met ".$host;
} else { // False
$this->connectie = "Connectie mislukt met ".$host;
}
}
$microtime_end = microtime_float(); // End Time
$microtime = $microtime_end - $microtime_start; // Time
$this->tijd += $microtime; // Total Time
}
//**Function Mysql_query**\\
function query($query) {
$microtime_start = microtime_float(); // Start Time
$this->querys ++; // Counter
$microtime_end = microtime_float(); // End Time
$microtime = $microtime_end - $microtime_start; // Time
$this->tijd += $microtime; // Totel Time
}
//**Function Mysql_num_rows**\\
function num_rows($query) {
$microtime_start = microtime_float(); // Start Time
$this->numrows ++; // Counter
$microtime_end = microtime_float(); // End Time
$microtime = $microtime_end - $microtime_start; // Time
$this->tijd += $microtime; // Total Time
}
//**Function Fetch_Assoc**\\
function fetch_assoc($query) {
$microtime_start = microtime_float(); // Start Time
$microtime_end = microtime_float(); // End Time
$microtime = $microtime_end - $microtime_start; // Total Time
$this->tijd += $microtime; // Total Time
$this->assocs ++; // Counter
}
//**Function Fetch_Object**\\
function fetch_object($query) {
$microtime_start = microtime_float(); // Start Time
$microtime_end = microtime_float(); // End Time
$microtime = $microtime_end - $microtime_start; // Total Time
$this->tijd += $microtime; // Total Time
$this->objects ++; // Counter
}
//**Function Fetch_Array**\\
function fetch_array($query) {
$microtime_start = microtime_float(); // Start Time
$microtime_end = microtime_float(); // End Time
$microtime = $microtime_end - $microtime_start; // Total Time
$this->tijd += $microtime; // Total Time
$this->arrays ++; // Counter
}
//**Function Set Increment**\\
function setIncrement($veld, $tabel) {
$array[] = $object->{$veld};
}
for ($i = 0; $i < count($array); $i++) { mysql_query("UPDATE ".$tabel." SET ".$veld." = ".($i + 1)." WHERE ".$veld." = ".$array[$i]); }
}
//**Function Error**\\
function _error ($error="") {
echo "Error: ".$error; // Echo: Var Error }
// Acties: Logboek/Statistieken
function getInfo() {
$return = "<h1>Statistics:</h1>";
$return .= "Connectie: ".$this->connectie."<br>";
$return .= "Count Querys: ".$this->querys."<br>";
$return .= "Count Fetch: ".($this->assocs + $this->arrays + $this->objects)."<br>";
$return .= "Count Fetch Assocs: ".$this->assocs."<br>";
$return .= "Count Fetch Arrays: ".$this->arrays."<br>";
$return .= "Count Fetch Objects: ".$this->objects."<br>";
$return .= "Count Num Rows: ".$this->numrows."<br>";
$return .= "Time: ".round($this->tijd,6); return $return;
}
}
//*Gebruik*\\
$sql = new SQL();
$sql->connect("localhost", "user", "pass", "db");
$query = $sql->query("SELECT * BLA WHERE BLA='BLA'");
while($assoc = $sql->fetch_assoc($query)) {
}
?>