Taking into account cookiesession and so on, I thought about it. I re-edited the parts of the previous database class that were incomplete.
Taking into account cookie session and so on, I thought about how to re-edit the previous incomplete database class:
Class opmysql {
Private $ host = "localhost"; // service period address
Private $ name = "root"; // logon account
Private $ pwd = ""; // password
Private $ database = "acaiji"; // database name
Private $ conn = ''; // database connection resource
Private $ result = ''; // result set
Private $ msg = ''; // return results
Private $ fields; // return Field
Private $ fieldsNum = 0; // number of returned fields
Private $ rowsNum = 0; // number of returned results
Private $ rowsRst = ''; // returns the field array of a single field.
Private $ filesArray = array (); // returns an array of fields.
Private $ rowsArray = array (); // array of returned results
// The application constructor initializes this class.
Function _ construct ($ host = '', $ name ='', $ pwd = '', $ database = ''){
If ($ host! = ''){
$ This-> host = $ host;
}
If ($ name! = ''){
$ This-> name = $ name;
}
If ($ pwd = ''){
$ This-> pwd = $ pwd;
}
If ($ database = ''){
$ This-> database = $ database;
}
}
// Connect to the database
Function link_conn (){
$ This-> conn = @ mysql_connect ($ this-> host, $ this-> name, $ this-> pwd );
Mysql_query ("set names utf8 ");
}
// Query results
Function mysql_query_arry ($ SQL ){
If ($ this-> conn = ''){
$ This-> link_conn ();
}
$ This-> result = mysql_query ($ SQL, $ this-> conn );
}
// Obtain the number of fields
Function getFileNum ($ SQL ){
If ($ this-> conn = ''){
$ This-> link_conn ();
}
$ This-> mysql_query_arry ($ SQL );
$ This-> fieldsNum = mysql_num_fields ($ this-> result );
}
// Obtain the number of query results
Function getRowsNum ($ SQL ){
$ This-> mysql_query_arry ($ SQL );
If (mysql_errno () = 0 ){
Return mysql_num_rows ($ this-> result );
} Else {
Return "this record is empty ";
}
}
// Retrieve the record array (single record)
Function rowsRst ($ SQL ){
$ This-> mysql_query_arry ($ SQL );
If (mysql_errno () = 0 ){
$ This-> rowsRst = mysql_fetch_array ($ this-> result, MYSQL_ASSOC );
Return $ this-> rowsRst;
} Else {
Return "this record array is empty ";
}
}
Function filesArray ($ SQL ){
$ This-> mysql_query_arry ($ SQL );
If (mysql_errno () = 0 ){
While ($ row = mysql_fetch_array ($ this-> result, MYSQL_ASSOC )){
$ This-> rowsArray () = $ row;
}
Return $ this-> rowsArray;
} Else {
Return "empty array set ";
}
}
Function uidrst ($ SQL ){
If ($ this-> conn = ''){
$ This-> link_conn ();
}
Mysql_query ($ SQL );
$ This-> rowsNum = mysql_affected_rows ();
If (mysql_errno () = 0 ){
Return $ this-> rowsNum;
} Else {
Return '';
}
}
// Obtain the corresponding field value
Function getFileds ($ SQL, $ fields ){
$ This-> mysql_query_arry ($ SQL );
If (mysql_errno () = 0 ){
If (mysql_num_rows ($ result)> 0 ){
$ Tmprows = mysql_fetch_row ($ result );
$ This-> fields = $ tmplogs [$ fields];
}
Return $ this-> fields;
} Else {
Return '';
}
}
// Error message
Function msg_error (){
If (mysql_errno () = 0 ){
$ This-> msg = mysql_errno ();
}
Return $ msg;
}
// Release the result set
Function close_rst (){
Mysql_free_result ($ this-> result );
$ This-> msg = '';
$ This-> fieldsNum = 0;
$ This-> rowsNum = 0;
$ This-> filesArray = '';
$ This-> rowsArray = '';
}
// Close the database connection
Function close_conn (){
$ This-> close_rst ();
Mysql_close ($ this-> conn );
$ This-> conn = '';
}
}
$ Conne = new opmysql ();
?>