51ff3226 |
1 | <?php |
2 | class result { |
3 | var $_numRows = 0; |
4 | var $_numFields = 0; |
5 | var $_currentRow = -1; |
6 | var $_currentRecord = array(); |
7 | var $_queryId = false; |
8 | var $_sql = ""; |
9 | |
10 | function result($queryId, $sql) { |
11 | $this->_queryId = $queryId; |
12 | $this->_sql = $sql; |
13 | if ($this->_queryId != false) { |
14 | $this->_numRows = @mysql_num_rows($this->_queryId); |
15 | $this->_numFields = @mysql_num_fields($this->_queryId); |
16 | $this->_currentRow = -1; |
17 | $this->_currentRecord = array(); |
18 | } else { |
19 | $this->exception("result failed."); |
20 | } |
21 | } |
22 | |
23 | function next() { |
24 | if ($this->_currentRow + 1 >= $this->_numRows) { |
25 | return false; |
26 | } else { |
27 | $this->_currentRecord = @mysql_fetch_assoc($this->_queryId); |
28 | $this->_currentRow++; |
29 | return true; |
30 | } |
31 | } |
32 | |
33 | function absolute($row) { |
34 | if ($row > 0) { |
35 | // positive row number |
36 | @mysql_data_seek($this->_queryId, $row-1); |
37 | $this->_currentRecord = @mysql_fetch_assoc($this->_queryId); |
38 | $this->_currentRow = $row; |
39 | } elseif ($row < 0) { |
40 | // not implemented yet |
41 | } else { |
42 | $this->exception("Cannot absolute position to row 0"); |
43 | } |
44 | } |
45 | |
46 | function getRecord() { |
47 | return $this->_currentRecord; |
48 | } |
49 | |
50 | function getString($column) { |
51 | if (is_int($column) == true) { |
52 | return (string)$this->_currentRecord[$column-1]; |
53 | } else { |
54 | return (string)$this->_currentRecord["$column"]; |
55 | } |
56 | } |
57 | |
58 | function getInt($column) { |
59 | if (is_int($column) == true) { |
60 | return (int)$this->_currentRecord[$column-1]; |
61 | } else { |
62 | return (int)$this->_currentRecord["$column"]; |
63 | } |
64 | } |
65 | |
66 | function getVariable($column) { |
67 | return (int)$this->_currentRecord["$column"]; |
68 | |
69 | } |
70 | |
71 | function getDouble() { |
72 | if (is_int($column) == true) { |
73 | return (double)$this->_currentRecord[$column-1]; |
74 | } else { |
75 | return (double)$this->_currentRecord["$column"]; |
76 | } |
77 | } |
78 | |
79 | function getRow() { |
80 | if ($this->_currentRow < 0) { |
81 | return 0; |
82 | } else { |
83 | return $this->_currentRow + 1; |
84 | } |
85 | } |
86 | |
87 | function getNumRows() { |
88 | return $this->_numRows; |
89 | } |
90 | |
91 | function getNumFields() { |
92 | return $this->_numFields; |
93 | } |
94 | |
95 | function exception($errorMsg) { |
96 | die("<pre>SQLException: ".$msg."</pre>"); |
97 | } |
98 | |
99 | } |
100 | |
101 | ?> |