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 Command

MySQL Command <? // Base SQL command class for MySQL operations class mysql_command { // Init variables required VAR $connobj = "" ; VAR $sqlstring = "" ; // Data related variables VAR $rs ; VAR $recordcount = 0 ; VAR $EOF = true ; VAR $lastid = 0 ; // Private methods function exec_command() { 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 = true ; $this->recordcount = mysql_affected_rows() ; $this->lastid = mysql_insert_id() ; $GLOBALS[$this->connobj]->msg = "\r\n" . date("d/m/Y - H:i:s") . " - OPERATION O.K.: Executed " . $this->sqlstring ." affected " . $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 " . mysql_errno() . " " . mysql_error() ; } } 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() ; } // Public interface function execute() { $this->exec_command() ; return $this->recordcount ; } function mysql_command($connobjname,$sqlcommand) { $this->connobj = $connobjname ; $this->sqlstring = $sqlcommand ; } } ?>