Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Php Programming Code Examples

Php > Database Related Code Examples

MySQL Recordset

MySQL Recordset <? // Base recordset class for MySQL operations class mysql_recordset { // Init variables required VAR $connobj = "" ; VAR $sqlstring = "" ; // Data related variables VAR $rs = 0 ; VAR $row = 0 ; VAR $recordcount = 0 ; VAR $EOF = true ; // Private methods function get_recordset() { if ($GLOBALS[$this->connobj]->db && $this->sqlstring!="") { $this->rs = mysql_query($this->sqlstring,$GLOBALS[$this->connobj]->db) ; $GLOBALS[$this->connobj]->error_level = mysql_errno() ; $GLOBALS[$this->connobj]->error_desc = mysql_error() ; if ($this->rs) { $this->EOF = false ; $this->recordcount = mysql_num_rows($this->rs) ; $GLOBALS[$this->connobj]->msg = "\r\n" . date("d/m/Y - H:i:s") . " - OPERATION O.K.: Executed " . $this->sqlstring ." got " . $this->recordcount . " rows" ; } else { $this->recordcount = 0 ; $this->EOF = true ; $GLOBALS[$this->connobj]->msg = "\r\n" . date("d/m/Y - H:i:s") . " - OPERATION FAILED: Executed " . $this->sqlstring . " got " . $GLOBALS[$this->connobj]->error_level . " " . $GLOBALS[$this->connobj]->error_desc ; } } else { $this->recordcount = 0 ; $this->EOF = true ; $GLOBALS[$this->connobj]->msg = "\r\n" . date("d/m/Y - H:i:s") . " - OPERATION FAILED: No database open OR no SQL command provided" ; } $GLOBALS[$this->connobj]->debug() ; } function get_row() { if ($this->rs && $GLOBALS[$this->connobj]->db) { $this->row = mysql_fetch_array($this->rs) ; $GLOBALS[$this->connobj]->error_level = mysql_errno() ; $GLOBALS[$this->connobj]->error_desc = mysql_error() ; // $GLOBALS[$this->connobj]->msg = "\r\n" . date("d/m/Y - H:i:s") . " - OPERATION Executed got " . $GLOBALS[$this->connobj]->error_level . " " . $GLOBALS[$this->connobj]->error_desc ; // $GLOBALS[$this->connobj]->debug() ; if ($this->row) { $this->EOF = false ; } else { $this->EOF = true ; } } else { $GLOBALS[$this->connobj]->msg = "\r\n" . date("d/m/Y - H:i:s") . " - OPERATION FAILED: No database open" ; } } // Public interface function query() { $this->get_recordset() ; return $this->recordcount ; } function movenext() { $this->get_row() ; return $this->EOF ; } function field($campo) { echo $this->row[$campo] ; } function value($campo) { return $this->row[$campo] ; } function mysql_recordset($connobjname,$sqlcommand) { $this->connobj = $connobjname ; $this->sqlstring = $sqlcommand ; } function clear_recordset() { $this->sqlstring="" ; mysql_free_result($this->rs) ; } function move_to($rnumber) { if ($this->rs) { if (!mysql_data_seek($this->rs,$rnumber)) { $GLOBALS[$this->connobj]->error_level = mysql_errno() ; $GLOBALS[$this->connobj]->error_desc = mysql_error() ; $GLOBALS[$this->connobj]->msg = "\r\n" . date("d/m/Y - H:i:s") . " - OPERATION FAILED: Could not move to record " . $rnumber . " " . $GLOBALS[$this->connobj]->error_level . " " . $GLOBALS[$this->connobj]->error_desc ; } else { $GLOBALS[$this->connobj]->msg = "\r\n" . date("d/m/Y - H:i:s") . " - OPERATION O.K.: Result pointer moved to " . $rnumber ; } } else { $GLOBALS[$this->connobj]->msg = "\r\n" . date("d/m/Y - H:i:s") . " - OPERATION FAILED: No result open" ; } $GLOBALS[$this->connobj]->debug() ; } function movefirst() { $this->move_to(0) ; } function movelast() { $this->move_to($this->recordcount-1) ; } } ?>