forked from jhaagsma/eemphyre-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMysqlDbResult.class.php
134 lines (108 loc) · 3.08 KB
/
MysqlDbResult.class.php
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
/**
* MysqlDbResult is the result object for the MysqlDb class
*
* PHP version 5
*
* ------
* These files are part of the empiresPHPframework;
* The original framework core (specifically the mysql.php
* the router.php and the errorlog) was started by Timo Ewalds,
* and rewritten to use APC and extended by Julian Haagsma,
* for use in Earth Empires (located at http://www.earthempires.com );
* it was spun out for use on other projects.
*
* The general.php contains content from Earth Empires
* written by Dave McVittie and Joe Obbish.
*
* The example website files were written by Julian Haagsma.
*
* @category Core
* @package EmPHyre
* @author Julian Haagsma <jhaagsma@gmail.com>
* @author Timo Ewalds <tewalds@gmail.com>
* @author Dave McVittie <dave.mcvittie@gmail.com>
* @author Joe Obbish <slagpit@earthempires.com>
* @license All files are licensed under the MIT License.
* @link https://github.com/jhaagsma/emPHyre
* @since Pulled out of MysqlDb.class.php 2016-03-15
*/
namespace EmPHyre;
class MysqlDbResult
{
public $dbcon;
public $result;
public $numrows;
public $affectedRows;
public $insertid;
public $querytime;
public function __construct($result, $dbcon, $numrows, $affectedRows, $insertid, $qt)
{
$this->dbcon = $dbcon;
$this->result = $result;
$this->numrows = $numrows;
$this->affectedRows = $affectedRows;
$this->insertid = $insertid;
$this->querytime = $qt;
}//end __construct()
public function __destruct()
{
$this->free();
}//end __destruct()
//one row at a time
public function fetchRow($type = DB_ASSOC)
{
return $this->result->fetch_array($type);
}//end fetchRow()
//for queries with a single column in a single row
public function fetchField()
{
$ret = $this->fetchRow(DB_NUM);
return $ret[0];
}//end fetchField()
//return the full set
public function fetchFieldSet()
{
$ret = [];
while ($line = $this->fetchRow(DB_NUM)) {
if (count($line) == 1) {
$ret[] = $line[0];
} else {
$ret[$line[0]] = $line[1];
}
}
return $ret;
}//end fetchFieldSet()
//return the full set
public function fetchRowSet($col = null, $type = DB_ASSOC)
{
$ret = [];
while ($line = $this->fetchRow($type)) {
if ($col) {
$ret[$line[$col]] = $line;
} else {
$ret[] = $line;
}
}
return $ret;
}//end fetchRowSet()
public function affectedRows()
{
return $this->affectedRows;
}//end affectedRows()
public function insertid()
{
return $this->insertid;
}//end insertid()
public function rows()
{
return $this->numrows;
}//end rows()
public function free()
{
if (!is_object($this->result)) {
return false;
}
return $this->result->free();
}//end free()
}//end class