<?phpclass opmysql{private $host = ' localhost ';//server address private $name = ' root ';//login Private $pwd = ' root ';//Login Password pri Vate $db = ' db ';//database name private $conn = ';//Database Link resource private $result = ';//result set private $msg = ';//return result private $fields; Returns the number of fields private $fieldsNum = 0;//Returns the number of results of the field $rowsNum the number of results of the returned row private $rowsRst = ';//returns an array of individual records private $fiel Dsarray = Array ();//returns the field array private $rowsArray = Array ();//returns multiple result arrays//initializes class function __construct ($host = ', $name = ', $pwd = ' ', $db = ') {if ($host = = ') {$this->host = $host;} if ($name = = ") {$this->name = $name;} if ($pwd = = ") {$this->pwd = $pwd;} if ($db = = ") {$this->db = $db;} $this->init_conn ();} Link database function Init_conn () {$this->conn = @mysql_connect ($this->host, $this->name, $this->pwd); @mysql_ select_db ($this->db, $this->conn); mysql_query ("Set names gb2312");} Query result set function Mysql_query_rst ($sql) {if ($this->conn== ") {$this->init_conn ();} $this->result = @mysql_query ($sql, $this->conn);} Get Field number Function Getfieldsnum ($sql) {$this->mysql_query_rst ($sql); $this->fieldsnum = @mysql_num_fields ($this->result) ;} Gets the total number of rows function Getrowsnum ($sql) {$this->mysql_query_rst ($sql); if (mysql_errno () = = 0) {return @mysql_num_rows ($ THIS->RESULT,MYSQL_ASSOC);} Else{return ';}} Gets the number of single records function Getrowsrst ($sql) {$this->mysql_query_rst ($sql); if (mysql_errno () = = 0) {$this->rowsrst =mysql _fetch_array ($this->RESULT,MYSQL_ASSOC); return $this->rowsrst;} Else{return ';}} Gets multiple records function Getrowsarray ($sql) {$this->mysql_query_rst ($sql), if (mysql_errno () = = 0) {while ($row = Mysql_fetch _array ($this->result,mysql_assoc) {$this->rowsarray[] = $row;} return $this->rowsarray;} Else{return ';}} Update, delete, insert record function Uidrst ($sql) {if ($this->conn = =) {$this->init_conn ();} @mysql_query ($sql); $this->rowsnum = Mysql_affected_rows (); if (mysql_errno () = = 0) {return $this->rowsnum;} Else{return ';}} Gets the number of fields corresponding to function GetFields ($sql, $fields) {$this->mysql_query_rst ($sql); if (Mysql_errno () == 0) {if (Mysql_num_fields ($this->result) > 0) {$tmp = @mysql_fetch_row ($this->result); $this->fieldsarray = $tmp [$fields]}return $this->fieldsarray;} Else{return ';}} Error message function Msg_error () {if (Mysql_errno ()! = 0) {$this->msg = Mysql_error ();} return $this->msg;} Release result set function Close_rst () {mysql_free_result ($this->result), $this->msg = "; $this->fieldsnum =0; $this- >rowsnum =0; $this->fieldsarray = "; $this->rowsarray =";} Close Database function Close_conn () {$this->close_rst (); Mysql_close ($this->conn); $this->conn = ';} $conne = new Opmysql ();}? >
MYQL type of source code