| 1 | <?php |
| 2 | /* This program is free software. It comes without any warranty, to |
| 3 | * the extent permitted by applicable law. You can redistribute it |
| 4 | * and/or modify it under the terms of the Do What The Fuck You Want |
| 5 | * To Public License, Version 2, as published by Sam Hocevar. See |
| 6 | * http://sam.zoy.org/wtfpl/COPYING for more details. */ |
| 7 | |
| 8 | class result { |
| 9 | var $_numRows = 0; |
| 10 | var $_numFields = 0; |
| 11 | var $_currentRow = -1; |
| 12 | var $_currentRecord = array(); |
| 13 | var $_queryId = false; |
| 14 | var $_sql = ""; |
| 15 | |
| 16 | function result($queryId, $sql) { |
| 17 | $this->_queryId = $queryId; |
| 18 | $this->_sql = $sql; |
| 19 | if ($this->_queryId != false) { |
| 20 | $this->_numRows = @mysql_num_rows($this->_queryId); |
| 21 | $this->_numFields = @mysql_num_fields($this->_queryId); |
| 22 | $this->_currentRow = -1; |
| 23 | $this->_currentRecord = array(); |
| 24 | } else { |
| 25 | $this->exception("result failed."); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | function next() { |
| 30 | if ($this->_currentRow + 1 >= $this->_numRows) { |
| 31 | return false; |
| 32 | } else { |
| 33 | $this->_currentRecord = @mysql_fetch_assoc($this->_queryId); |
| 34 | $this->_currentRow++; |
| 35 | return true; |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | function absolute($row) { |
| 40 | if ($row > 0) { |
| 41 | // positive row number |
| 42 | @mysql_data_seek($this->_queryId, $row-1); |
| 43 | $this->_currentRecord = @mysql_fetch_assoc($this->_queryId); |
| 44 | $this->_currentRow = $row; |
| 45 | } elseif ($row < 0) { |
| 46 | // not implemented yet |
| 47 | } else { |
| 48 | $this->exception("Cannot absolute position to row 0"); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | function getRecord() { |
| 53 | return $this->_currentRecord; |
| 54 | } |
| 55 | |
| 56 | function getString($column) { |
| 57 | if (is_int($column) == true) { |
| 58 | return (string)$this->_currentRecord[$column-1]; |
| 59 | } else { |
| 60 | return (string)$this->_currentRecord["$column"]; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | function getInt($column) { |
| 65 | if (is_int($column) == true) { |
| 66 | return (int)$this->_currentRecord[$column-1]; |
| 67 | } else { |
| 68 | return (int)$this->_currentRecord["$column"]; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | function getVariable($column) { |
| 73 | return (int)$this->_currentRecord["$column"]; |
| 74 | |
| 75 | } |
| 76 | |
| 77 | function getDouble() { |
| 78 | if (is_int($column) == true) { |
| 79 | return (double)$this->_currentRecord[$column-1]; |
| 80 | } else { |
| 81 | return (double)$this->_currentRecord["$column"]; |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | function getRow() { |
| 86 | if ($this->_currentRow < 0) { |
| 87 | return 0; |
| 88 | } else { |
| 89 | return $this->_currentRow + 1; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | function getNumRows() { |
| 94 | return $this->_numRows; |
| 95 | } |
| 96 | |
| 97 | function getNumFields() { |
| 98 | return $this->_numFields; |
| 99 | } |
| 100 | |
| 101 | function exception($errorMsg) { |
| 102 | die("<pre>SQLException: ".$msg."</pre>"); |
| 103 | } |
| 104 | |
| 105 | } |
| 106 | |
| 107 | ?> |