PHP code:
PHP
/ **
* @ Page: Class.Mysql.php
* @ Copyright: Snakevil, 1998-2004
* @ Author: Snakevil
*
* @ Usage:
* Defines the MYSQL database operation class.
*
* @ Notes:
* 3:30 2004-6-6
* Stately complete the original version.
* /
/ ** - Content Start ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------- * /
IF (Defined ('SWORK_COPYRIGHT') && SWORK_COPYRIGHT === 'Snakevil 1998-2004') {
/ ** class package start * /
/ **
* @ Purpose:
* _SWork_Rabrry Database class MySQL
* @ Package name: mysql
* @ Author: Snakevil
* @ Modifications:
*
* @ See Alse:
* /
Class fwsnvmysql extends fWSNVBASECLASS {
/ **
* @ Purpose:
* server address
* @ Attribute Name: MHOST
* @ Type: String
* /
Var $ MHOST;
/ **
* @ Purpose:
* Database user
* @ Attribute Name: Muser
* @ Type: String
* /
Var $ muse;
/ **
* @ Purpose:
* Database password
* @ Attribute name: MPassword
* @ Type: String
* /
Var $ mpassword;
/ **
* @ Purpose:
* Name database
* @ Attribute Name: MDBNAME
* @ Type: String
* /
Var $ mdbname;
/ **
* @ Purpose:
* Database table prefix
* @ Attribute Name: MTBLPREFIX
* @ Type: String
* /
VAR $ mtblprefix;
/ **
* @ Purpose:
* Connection resource number
* @ Attribute Name: MLINKID
* @ Type: resource
* /
Var $ mlinkid;
/ **
* @ Purpose:
* Handling resource numbers
* @ Attribute Name: MQueryID
* @ Type: resource
* /
Var $ mQueryid;
/ **
* @ Purpose:
* Reference Search Resources
* @ Attribute name: resultS
* @ Type: Reference fWSNVMYSQLRSET
* /
Var $ Results;
/ **
* @ Purpose:
* Search results index
* @ Attribute Name: Misbufferd
* @ Type: Boolean
* /
Var $ misbuffer;
/ **
* @ Purpose:
* Save the final execution SQL statement
* @ Attribute Name: Mlastsql
* @ Type: string * /
Var $ mlastsql;
/ **
* @ Purpose:
* The number of data rows affecting the last SQL statement
* @ Attribute name: mlastaffectd
* @ Type: Integer
* /
VAR $ mlastaffectd;
/ **
* @ Purpose:
* Last SQL :: INSERT statement Number
* @ Attribute name: mlastInsertd
* @ Type: Integer
* /
Var $ mlastinsertd;
/ **
* @ Ionize method @
* @ Parameters:
* String $ _HOST server address
* String $ _USER Database User
* String $ _Password database password
* String $ _dbname database name
* String $ _TBLPREFIX Database table prefix
* /
Function fWSNVMYSQL ($ _ host = '', $ _USER = ', $ _Password =', $ _dbname = ', $ _TBLPREFIX =') {
Parent :: fwsnvbaseclass ();
$ this-> mlinkid = 0;
$ this-> mQueryid = 0;
$ this-> mlasttblname = '';
$ this-> Results = null;
$ this-> misfferd = true;
$ this-> mlastsql = '';
$ this-> mlastaffectd = -1;
$ this-> mlastinsertd = -1;
$ this-> MHOST = (is_string ($ _ host))? $ _host: '';
$ this-> muser = (is_string ($ _ user))? $ _USER: '';
$ this-> mpassword = (is_string ($ _ password))? $ _password: '';
$ this-> mdbname = (is_string ($ _ dbname))? $ _dbname: '';
$ this-> MTBLPREFIX = (is_string ($ _ tblprefix))? $ _TBLPREFIX: '';
IF ($ this-> MHOST! = ') $ this-> connect ();
}
/ **
* @ Purpose:
* Connect the database server.
* @METHOD name: connect ()
* @ Parameters:
* String $ _HOST server address
* String $ _USER Database User
* String $ _Password database password
* String $ _dbname database name
* String $ _TBLPREFIX Database table prefix
* @ RETURN: Boolean connection is successful
* /
Function Connect ($ _ host = '', $ _USER = ', $ _Password =', $ _dbname = ', $ _TBLPREFIX =' ') {IF ($ this-> iSerror ()) Return False;
/ ** If the connection parameters are connected, the same connection parameters are maintained, otherwise the original connection is re-connected * /
IF (is_Resource ($ this-> mlinkid) {
IF ($ this-> MHOST == $ _host) return true;
Else {
$ this-> close ();
}
}
/ ** will overwrite the original attribute value of the parameter value inequality * /
IF (is_string ($ _ host)
&& $ _HOST! = $ This-> MHOST
&& $ _HOST! = '')
$ this-> MHOST = $ _host;
IF (is_string ($ _ user)
&& $ _USER! = $ This-> Muser &&
$ _USER! = '')
$ this-> muser = $ _user;
IF (is_string)
&& $ _Password! = $ This-> mpassword
&& $ _password! = ')
$ this-> mpassword = $ _password;
IF (is_string ($ _ DBNAME)
&& $ _DBNAME! = $ This-> mdbname
&& $ _DBNAME! = ')
$ this-> mdbname = $ _dbname;
IF (is_string), i ($ _ TBLPREFIX)
&& $ _TBLPREFIX! = $ This-> MTBLPREFIX
&& $ _TBLPREFIX! = '')
$ this-> mtblprefix = $ _TBLPREFIX;
IF ($ this-> MHOST! = ') {
$ this-> mlinkid = @mysql_connect ($ this-> MHOST, $ this-> Muser, $ this-> password);
IF (is_Resource ($ this-> mlinkid) {
IF ($ this-> mdbname! = ')
$ this-> selectdb ();
Return True;
}
}
/** Connection failed */
$ this-> mlinkid = 0;
Return $ this-> Error (2);
}
/ **
* @ Purpose:
* Select the database.
* @METHOD name: selectdb ()
* @ Parameters:
* String $ _dbname database name
* @ RETURN: Boolean Select whether it is successful
* /
Function selectdb ($ _ dbname = '') {
IF ($ this-> iSerror ()) Return False;
IF (is_string ($ _ dbname) && $ _dbname! = ') $ this-> mdbname = $ _dbname; / ** Mandatory Database When you have not connected database * /
IF (! is_resource ($ this-> mlinkid) Return $ this-> connect ();
IF (@MYSQL_SELECT_DB ($ this-> mdbname, $ this-> mlinkid))
Return True;
Else {
/ ** Unable to select the corresponding database, return to errors * /
Return $ this-> Error (3);
}
}
/ **
* @ Purpose:
* Set whether the search result is cache
* @Method name: setBuffertype ()
* @ Parameters:
* Boolean $ _ISBufferD to cache results
* @ Return: Boolean setting success
* /
Function setBuffertype ($ _ isbufferd = true) {
IF ($ this-> iSerror ()) Return False;
IF ($ _ISBufferd == 1) $ this-> misfferd = true;
Else IF ($ _ISBufferd == 0) $ this-> misbufferd = false;
Else $ this-> misfferd = true;
Return True;
}
/ **
* @ Purpose:
* Execute SQL statement
* @METHOD name: Execute ()
* @ Parameters:
* String $ _SQL SQL statement to be executed
* Boolean $ _ISBufferD to cache results
* @ RETURN: BOOLEAN does not perform success
* /
Function Execute ($ _ SQL = '', $ _ISBufferd = 8486) {
IF ($ this-> iSerror ()) Return False;
/ ** If the server is not connected, try connecting * /
IF (! is_resource ($ this-> mlinkid) && false === $ this-> connect ())
Return False;
IF (! is_string ($ _ SQL)) Return False;
IF ($ _ISBufferd! = 1 && $ _isbufferd! = 0)
$ _ISBUFFERD = $ this-> misfferd;
$ comMMAND = ($ _ISBufferd)? 'mysql_query': 'MySQL_UNBUFFERED_QUERY';
IF ($ _ISBufferd) {
$ this-> mQueryid = @Mysql_Query ($ _ SQL, $ this-> mlinkid);
IF (false === $ this-> mQueryid) {
/ ** Cannot handle the SQL statement correctly, return an error * /
Return $ this-> Error (4);
}
$ this-> mlastsql = $ _sql;
$ this-> mlastaffectd = -1;
$ this-> mlastinsertd = -1;
$ this-> results = null; / ** Get the keywords for the current SQL statement * /
$ wrap_pos = strpos ($ _ SQL, '');
IF (false === $ wrap_pos $ key_word = $ _sql;
Else $ key_word = substr ($ _ SQL, 0, $ Wrap_POS);
$ key_word = strtolower ($ key_word);
Switch ($ Key_word) {
Case 'INSERT':
$ this-> mlastinsertd = mysql_insert_id ($ this-> mlinkid);
Case 'Delete':
Case 'Replace':
Case 'Update':
$ this-> mlastaffectd = mysql_affected_rows ($ this-> mlinkid);
Break;
Case 'SELECT':
Case 'Show':
Case 'Describe':
Case 'Explain:
$ this-> Results = & new fwsnvmysqlrset ($ this-> mlinkid, $ this-> mqueryid);
DEFAULT:
}
} else {
IF (false === @MYSQL_UNBUFFERED_QUERY ($ _ SQL, $ THIS-> MLINKID)) {
/ ** Cannot handle the SQL statement correctly, return an error * /
Return $ this-> Error (4);
}
$ this-> mlastsql = $ _sql;
$ this-> mlastaffectd = -1;
$ this-> mlastinsertd = -1;
$ this-> Results = null;
}
Return True;
}
/ ** - Methods Following: Trying to Simplify SQL Process --------------------- * /
/ **
* @ Purpose:
* Execute SQL :: INSERT statement
* @Method name: INSERT ()
* @ Parameters:
* Boolean $ _ISBufferD to cache results
* Mixed $ _TBLPREFIX Table Name Prefix
* String $ _TBLNAME Table Name
* Mixed $ _fields To add the field
* Mixed $ _VALUES_N to add the nth value
* @ RETURN: BOOLEAN does not perform success
* @ See Also:
* This method is not necessarily, and the order is $ _ISBufferd, $ _TBLPREFIX, $ _TBLNAME,
* $ _Fields, all of which have all parameters are the value to be added
* /
Function INSERT () {
IF ($ this-> iSerror ()) Return False;
$ arg_count = func_num_args ();
IF ($ arg_count <5) Return False;
$ FUNC_ARGS = FUNC_GET_ARGS ();
$ _ISBUFFERD = $ func_args [0];
/ ** The name of the table that is processed is processed * /
$ _SQL = ($ FUNC_ARGS [1] == SWORK_DEFAULT) $ this-> MTBLPREFIX
: $ FUNC_ARGS [1];
$ _SQL = 'INSERT INTO `' .addslashes ($ _ SQL. $ FUNC_ARGS [2]). '` (`';
/ ** Get list of fields to add * /
$ _SQL. = (Is_ARRAY ($ FUNC_ARGS [3])))
Addslashes (Implode ('`,`', $ func_args [3]))))
: addslashes ($ FUNC_ARGS [3]);
$ _SQL. = '`) Values (' ';
/ ** Process the value to be added * /
$ t_ARR = array ();
For ($ I = 0, $ j = $ arg_count - 4; $ i $ t_arr [] = (is_ARRAY ($ FUNC_ARGS [$ I])) ? STR_REPLACE ('-% sqv0te% -', '', addslashes (Implode ('-% sqv0te% -, -% sqv0te% -', $ FUNC_ARGS [$ I])))))) : addslashes ($ FUNC_ARGS [$ I]); } $ _SQL. = Implode (''), ('', $ t_arr). '') '; Return $ this-> Execute ($ _ SQL, $ _ISBuffer); } / ** * @ Purpose: * Execute SQL:
转载请注明原文地址:https://www.9cbs.com/read-112259.html