-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasses.php
More file actions
70 lines (56 loc) · 1.81 KB
/
classes.php
File metadata and controls
70 lines (56 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
class php_query {
/* Member functions and variables go here */
var $name;
var $query;
var $result;
var $starttime, $endtime, $queryDuration, $totalDuration;
var $fieldCount, $rowCount;
var $JSON_data = array();
function convertToJSON(){
//json encoding
$json_temp = array();
//only do this if there is at least one row in the results
if($this->rowCount>0){
mysql_data_seek( $this->result, 0);
while($r = mysql_fetch_assoc($this->result)) {
$json_temp[] = $r;
}
$this->JSON_data = $json_temp;
}
return $json_temp;
}
function runQuery($queryString){
global $debug;
//$myQuery = new php_query;
$this->query = $queryString;
$this->starttime = microtime(true);
//$this->result = mysql_unbuffered_query($queryString);
$this->result = mysql_query($queryString);
$this->endtime = microtime(true);
$this->queryDuration = $this->endtime - $this->starttime;
$this->fieldCount = mysql_num_fields($this->result);
$this->rowCount = mysql_num_rows($this->result);
//convert the sql response to JSON
$this->convertToJSON();
$this->endtime = microtime(true);
$this->totalDuration = $this->endtime - $this->starttime;
//output if debug is enabled
if($debug){
echo "<b>Query {$this->name}</b>";
echo "<br>Query: " . $this->query;
echo "<br>Total Fields: " . $this->fieldCount;
echo "<br>Total Rows: " . $this->rowCount;
echo "<br>Query Duration: " . number_format($this->queryDuration, 2) . " sec";
echo "<br>Total Duration: " . number_format($this->totalDuration, 2) . " sec";
echo "<br>";
}
return $this;
}
function createJSVar($varName){
global $debug;
echo "<script>{$varName} = " . json_encode($this->JSON_data) . ";</script>";
return $this;
}
}
?>