|
Revision 1688, 1.7 KB
(checked in by driehle, 11 months ago)
|
|
Converted all files to UTF-8 and added accept-charset="UTF-8" to most forms.
|
| Line | |
|---|
| 1 | <?php |
|---|
| 2 | // call database class |
|---|
| 3 | class Query { |
|---|
| 4 | // Variablen |
|---|
| 5 | var $_sql = ""; |
|---|
| 6 | var $_result = 0; |
|---|
| 7 | var $_errno = 0; |
|---|
| 8 | var $_error = ""; |
|---|
| 9 | |
|---|
| 10 | //Konstruktor |
|---|
| 11 | function Query($sql) |
|---|
| 12 | { |
|---|
| 13 | // Query in der Klasse speichern |
|---|
| 14 | $this->_sql = trim($sql); |
|---|
| 15 | $this->_result = mysql_query($this->_sql); |
|---|
| 16 | if(!$this->_result) { |
|---|
| 17 | $this->_errno = mysql_errno(); |
|---|
| 18 | $this->_error = mysql_error(); |
|---|
| 19 | } |
|---|
| 20 | } |
|---|
| 21 | |
|---|
| 22 | //Methoden |
|---|
| 23 | function error() |
|---|
| 24 | { |
|---|
| 25 | // Result-ID in einer tmp-Variablen speichern |
|---|
| 26 | $tmp = $this->_result; |
|---|
| 27 | // Variable in boolean umwandeln |
|---|
| 28 | $tmp = (bool)$tmp; |
|---|
| 29 | // Variable invertieren |
|---|
| 30 | $tmp = !$tmp; |
|---|
| 31 | // und zurÃŒckgeben |
|---|
| 32 | return $tmp; |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | function getError() { |
|---|
| 36 | if($this->error()) { |
|---|
| 37 | $str = "request:\n".$this->_sql."\n"; |
|---|
| 38 | $str .= "response:\n".$this->_error."\n"; |
|---|
| 39 | $str .= "Errorcode: ".$this->_errno; |
|---|
| 40 | } |
|---|
| 41 | else $str = "No error."; |
|---|
| 42 | return $str; |
|---|
| 43 | } |
|---|
| 44 | function getErrno() { |
|---|
| 45 | return $this->_errno; |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | function fetch() { |
|---|
| 49 | if($this->error()) { |
|---|
| 50 | echo "An Error has occurred, please check your MySQL-Query."; |
|---|
| 51 | $return = null; |
|---|
| 52 | } |
|---|
| 53 | else $return = mysql_fetch_assoc($this->_result); |
|---|
| 54 | return $return; |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | function numRows() { |
|---|
| 58 | if($this->error()) { |
|---|
| 59 | $return = -1; |
|---|
| 60 | } |
|---|
| 61 | else $return = mysql_num_rows($this->_result); |
|---|
| 62 | return $return; |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | function free() { |
|---|
| 66 | // Speicher freimachen |
|---|
| 67 | mysql_free_result($this->_result); |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | } |
|---|
| 71 | ?> |
|---|