MySQL class

xiaoxiao2021-03-06  61

PHP code:

/ **

* @ 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: > ELETE statement</p>
<p>* @Method name: delete ()</p>
<p>* @ Parameters:</p>
<p>* Boolean $ _ISBufferD to cache results</p>
<p>* Mixed $ _TBLPREFIX Table Name Prefix</p>
<p>* String $ _TBLNAME Table Name</p>
<p>* String $ _whereclause Retrieval Conditions</p>
<p>* String $ _LIMITCLAUSE limit processing data record number</p>
<p>* @ RETURN: BOOLEAN does not perform success</p>
<p>* /</p>
<p>Function delete ($ _ isbufferd = 8486, $ _TBLPREFIX = ', $ _TBLNAME =', $ _whereclause = ', $ _LIMITCLASE =') {</p>
<p>IF ($ this-> iSerror ()) Return False;</p>
<p>$ _SQL = ($ _TBLPREFIX == SWORK_DEFAULT)</p>
<p>? $ this-> MTBLPREFIX</p>
<p>: $ _TBLPREFIX;</p>
<p>$ _SQL = 'delete from `' .addslashes ($ _ SQL. $ _ TBLNAME). '`';</p>
<p>IF ($ _whereclause! = ') $ _SQL. =' WHERE '. $ _ whereclause;</p>
<p>IF (is_int ($ _ limitedclause)) $ _SQL. = 'Limit'. $ _ limitcLaSe;</p>
<p>Return $ this-> Execute ($ _ SQL, $ _ISBufferd);</p>
<p>/ **</p>
<p>* @ Purpose:</p>
<p>* Execute SQL :: Replace statement</p>
<p>* @METHOD name: Replace ()</p>
<p>* @ Parameters:</p>
<p>* Boolean $ _ISBufferD to cache results</p>
<p>* Mixed $ _TBLPREFIX Table Name Prefix</p>
<p>* String $ _TBLNAME Table Name</p>
<p>* Mixed $ _fields To change the field</p>
<p>* Mixed $ _VALUES To change the value</p>
<p>* @ RETURN: BOOLEAN does not perform success</p>
<p>* /</p>
<p>Function Replace ($ _ isbufferd = 8486, $ _TBLPREFIX = ', $ _TBLNAME =', $ _fields = '', $ _VALUES = ') {</p>
<p>IF ($ this-> iSerror ()) Return False;</p>
<p>$ _SQL = ($ _TBLPREFIX == SWORK_DEFAULT)</p>
<p>? $ this-> MTBLPREFIX</p>
<p>: $ _TBLPREFIX;</p>
<p>$ _SQL = 'Replace INTO `' .addslashes ($ _ SQL. $ _ TBLNAME). '` (`';</p>
<p>/ ** Get list of fields to add * /</p>
<p>$ _SQL. = (Is_ARRAY ($ _ fields))</p>
<p>? addslashes (Implode ('`,`', $ _fields))</p>
<p>: addslashes ($ _ fields);</p>
<p>$ _SQL. = '`) Values ​​(' ';</p>
<p>/ ** Process the value to be added * /</p>
<p>$ _SQL. = (Is_ARRAY ($ _ value))</p>
<p>? STR_REPLACE ('-% sqv0te% -', '', addslashes (Implode ('-% sqv0te% -, -% sqv0te% -', $ _values)))))</p>
<p>: addslashes ($ _ VALUES);</p>
<p>$ _SQL. = '') ';</p>
<p>Return $ this-> Execute ($ _ SQL, $ _ISBuffer);</p>
<p>}</p>
<p>/ **</p>
<p>* @ Purpose:</p>
<p>* Execute SQL :: UPDATE statement</p>
<p>* @Method name: Update ()</p>
<p>* @ Parameters:</p>
<p>* Boolean $ _ISBufferD to cache results</p>
<p>* Mixed $ _TBLPREFIX Table Name Prefix</p>
<p>* String $ _TBLNAME Table Name</p>
<p>* Mixed $ _fields To update the field</p>
<p>* Mixed $ _VALUES To update the value</p>
<p>* String $ _whereclause Retrieval Conditions</p>
<p>* String $ _LIMITCLAUSE limit processing data record number</p>
<p>* @ RETURN: BOOLEAN does not perform success</p>
<p>* /</p>
<p>Function update ($ _ isbufferd = 8486, $ _TBLPREFIX = ', $ _TBLNAME =', $ _fields = ', $ _values ​​=', $ _whereclause = ', $ _LIMITCLASE =') {</p>
<p>IF ($ this-> iSerror ()) Return False;</p>
<p>$ _SQL = ($ _TBLPREFIX == SWORK_DEFAULT)? $ This-> MTBLPREFIX</p>
<p>: $ _TBLPREFIX;</p>
<p>$ _SQL = 'Update `' .addslashes ($ _ SQL. $ _ TBLNAME). '` Set'</p>
<p>IF (! is_ARRAY ($ _ fields)) $ _fields = array ($ _ fields);</p>
<p>If (! is_ARRAY ($ _ VALUES)) $ _VALUES = Array ($ _ VALUES);</p>
<p>$ value_count = count ($ _ values);</p>
<p>For ($ i = 0, $ j = count ($ _ fields); $ i <j; $ i   ) {</p>
<p>IF ($ I) $ _SQL. = ',';</p>
<p>$ _SQL. = '`' .Addslashes ($ _ fields [$ I]). '` =' ';</p>
<p>$ _SQL. = ($ I <$ VALUE_COUNT)</p>
<p>? addslashes ($ _ VALUES [$ I])</p>
<p>: '';</p>
<p>$ _SQL. = '' ';</p>
<p>}</p>
<p>IF ($ _whereclause! = ') $ _SQL. =' WHERE '. $ _ whereclause;</p>
<p>IF (is_int ($ _ limitedclause)) $ _SQL. = 'Limit'. $ _ limitcLaSe;</p>
<p>Return $ this-> Execute ($ _ SQL, $ _ISBuffer);</p>
<p>}</p>
<p>/ **</p>
<p>* @ Purpose:</p>
<p>* Execute SQL :: SELECT ... JOIN ... JOIN]</p>
<p>* @Method name: Join ()</p>
<p>* @ Parameters:</p>
<p>* Mixed $ _TBLPREFIX Table Name Prefix</p>
<p>* String $ _TBLNAME Table Name</p>
<p>* String $ _AlaiasName</p>
<p>* String $ _whereclause matching conditions</p>
<p>* String $ _OTHERJOIN Other join statement</p>
<p>* @ RETURN: Mixed generated SQL statement</p>
<p>* /</p>
<p>Function Join ($ _ TBLPREFIX = ', $ _TBLNAME =', $ _ALIASNAME = ', $ _whereclause =', $ _ portherjoin = '') {</p>
<p>IF ($ this-> iSerror ()) Return False;</p>
<p>$ _SQL = ($ _TBLPREFIX == SWORK_DEFAULT)</p>
<p>? $ this-> MTBLPREFIX</p>
<p>: $ _TBLPREFIX;</p>
<p>$ _SQL = 'Left Join `' .addslashes ($ _ SQL. $ _ TBLNAME). '`';</p>
<p>IF ($ _ALIASNAME! = ') $ _SQL. =' AS `'.addslashes ($ _ aliasname).'` ';</p>
<p>$ _SQL. = 'ON'. $ _ Whereclause;</p>
<p>IF ($ _OTHERJOIN! = ') $ _SQL. =' '. $ _ otherjoin;</p>
<p>Return $ _SQL;}</p>
<p>/ **</p>
<p>* @ Purpose:</p>
<p>* Execute SQL :: SELECT statement</p>
<p>* @Method name: select ()</p>
<p>* @ Parameters:</p>
<p>* Boolean $ _ISBufferD to cache results</p>
<p>* Mixed $ _TBLPREFIX Table Name Prefix</p>
<p>* String $ _TBLNAME Table Name</p>
<p>* String $ _AlaiasName</p>
<p>* Mixed $ _fields to retrieve the fields</p>
<p>* String $ _OTHERJOIN Other join statement</p>
<p>* String $ _whereclause matching conditions</p>
<p>* String $ _ORDERBYCLASE Sort</p>
<p>* String $ _GroupByClause packet simplified way</p>
<p>* String $ _LIMITCLAUSE limit processing data record number</p>
<p>* String $ _OFFSetClause Restricted Data Offset</p>
<p>* @ RETURN: BOOLEAN does not perform success</p>
<p>* /</p>
<p>function Select ($ _ IsBufferd = 8486, $ _TblPrefix = '', $ _TblName = '', $ _AliasName = '', $ _Fields = '', $ _OtherJoin = '', $ _WhereClause = '', $ _LimitClause = '', $ _ORDERBYCLASE = ', $ _offsetclause =', $ _GROUPBYCLAS = ') {</p>
<p>IF ($ this-> iSerror ()) Return False;</p>
<p>$ _SQL = ($ _TBLPREFIX == SWORK_DEFAULT)</p>
<p>? $ this-> MTBLPREFIX</p>
<p>: $ _TBLPREFIX;</p>
<p>$ _SQL = 'SELECT' .addslashes ($ _ fields). 'From `'</p>
<p>.addslashes ($ _ sql. $ _ tblname). '`';</p>
<p>IF ($ _ALIASNAME! = ') $ _SQL. =' AS `'.addslashes ($ _ aliasname).'` ';</p>
<p>IF ($ _OTHERJOIN! = ') $ _SQL. =' '. $ _ otherjoin;</p>
<p>IF ($ _whereclause! = ') $ _SQL. =' WHERE '. $ _ whereclause;</p>
<p>IF ($ _GROUPBYCLAUSE! = ') $ _SQL. =' Group by '. $ _ groupbyclause;</p>
<p>IF ($ _ORDERBYCLASE! = ') $ _SQL. =' ORDER BY '. $ _ ORDERBYCLASE</p>
<p>IF (IS_INT ($ _ Limitclause) {</p>
<p>$ _SQL. = 'Limit';</p>
<p>IF (is_int ($ _ offsetclause)) $ _SQL. = $ _offsetclause. ',';</p>
<p>$ _SQL. = $ _LIMITCLASE;</p>
<p>}</p>
<p>Return $ this-> Execute ($ _ SQL, $ _ISBuffer);</p>
<p>}</p>
<p>/ ** - Methods Above: Trying to Simplify SQL Process -------------------------- * /</p>
<p>/ **</p>
<p>* @ Purpose:</p>
<p>* Get the number obtained by the SQL :: INSERT statement.</p>
<p>* @Method name: getInserted ()</p>
<p>* @ RETURN: MIXED Return Number</p>
<p>* /</p>
<p>Function getInserted () {</p>
<p>IF ($ this-> iSerror ()) Return False;</p>
<p>IF ($ this-> mlastinsertd == -1) Return False;</p>
<p>Return $ this-> mlastinsertd;</p>
<p>}</p>
<p>/ **</p>
<p>* @ Purpose:</p>
<p>* Get the number of data affected by the SQL statement.</p>
<p>* @Method name: getAffected ()</p>
<p>* @ RETURN: Mixed Return Return</p>
<p>* /</p>
<p>Function getAffected () {</p>
<p>IF ($ this-> iSerror ()) Return False;</p>
<p>IF ($ this-> mlastaffectd == -1) Return False;</p>
<p>Return $ this-> mlastaffectd;</p>
<p>}</p>
<p>/ **</p>
<p>* @ Purpose:</p>
<p>* Release the search resource.</p>
<p>* @METHOD name: FreeResult ()</p>
<p>* @ Return: Boolean released success</p>
<p>* /</p>
<p>Function freresult () {</p>
<p>IF ($ this-> iSerror ()) Return False;</p>
<p>IF (isset ($ this-> results) {</p>
<p>$ this-> results-> close ();</p>
<p>$ this-> Results = null;</p>
<p>$ this-> mlastaffectd = -1;</p>
<p>$ this-> mlastinsertd = -1;</p>
<p>}</p>
<p>Return True;</p>
<p>}</p>
<p>/ **</p>
<p>* @ Purpose:</p>
<p>* Disconnect the database connection.</p>
<p>* @METHOD name: Close ()</p>
<p>* @ Return: Boolean disconnected success</p>
<p>* /</p>
<p>Function close () {</p>
<p>IF ($ this-> iSerror ()) Return False;</p>
<p>IF (is_Resource ($ this-> mlinkid) {</p>
<p>/ ** Release retrieval resource * /</p>
<p>$ this-> freresult ();</p>
<p>@MYSQL_Close ($ this-> mlinkid);</p>
<p>$ this-> mlinkid = 0;</p>
<p>$ this-> MHOST = '';</p>
<p>$ this-> muser = ';</p>
<p>$ this-> mpassword = '';</p>
<p>$ this-> mdbname = '';</p>
<p>$ this-> mtblprefix = '';</p>
<p>}</p>
<p>Return True;</p>
<p>}</p>
<p>}</p>
<p>/ **</p>
<p>* @ Purpose:</p>
<p>* _SWork_Companic Data Set of Database Class Mysql</p>
<p>* @ Package name: mysqlrset</p>
<p>* @ Author: Snakevil</p>
<p>* @ Modifications:</p>
<p>*</p>
<p>* @ See Alse:</p>
<p>* /</p>
<p>Class fWSNVMYSQLRSET EXTENDS FWSNVBASECLASS {</p>
<p>/ **</p>
<p>* @ Purpose:</p>
<p>* Reference Database connection</p>
<p>* @ Attribute Name: MLINKID</p>
<p>* @ Type: Reference Resource</p>
<p>* /</p>
<p>Var $ mlinkid;</p>
<p>/ **</p>
<p>* @ Purpose:</p>
<p>* Retrieve database retrieval</p>
<p>* @ Attribute Name: MQueryID</p>
<p>* @ Type: Reference Resource</p>
<p>* /</p>
<p>Var $ mQueryid;</p>
<p>/ **</p>
<p>* @ Purpose:</p>
<p>* Total number of retrieval data columns</p>
<p>* @ Attribute Name: MROWTOTAL</p>
<p>* @ Type: Integer</p>
<p>* /</p>
<p>Var $ mrowtotal;</p>
<p>/ **</p>
<p>* @ Purpose:</p>
<p>* Total number of searches for data set fields</p>
<p>* @ Attribute name: mfieldtotal</p>
<p>* @ Type: Integer</p>
<p>* /</p>
<p>Var $ mfieldtotal;</p>
<p>/ **</p>
<p>* @ Purpose:</p>
<p>* Retrieval mode</p>
<p>* @ Attribute name: mfetchmode</p>
<p>* @ Type: Constant</p>
<p>* /</p>
<p>Var $ mfetchmode;</p>
<p>/ **</p>
<p>* @ Purpose:</p>
<p>* Field data collection</p>
<p>* @ Attribute Name: Mfields</p>
<p>* @ Type: Array</p>
<p>* /</p>
<p>Var $ mfields;</p>
<p>/ **</p>
<p>* @ Purpose:</p>
<p>* Data set pointer</p>
<p>* @ Attribute name: MPOINTER</p>
<p>* @ Type: Integer</p>
<p>* /</p>
<p>Var $ mpoint;</p>
<p>/ **</p>
<p>* @ Purpose:</p>
<p>* Data collection of current data lines</p>
<p>* @ Attribute Name: Mrowdata</p>
<p>* @ Type: Array</p>
<p>* /</p>
<p>Var $ MROWDATA;</p>
<p>/ **</p>
<p>* @ Ionize method @</p>
<p>* @ Parameters:</p>
<p>* Reference Resource $ _LINKID Database Connection</p>
<p>* Reference resource $ _QUERYID database retrieval</p>
<p>* /</p>
<p>Function fWSNVMYSQLRSET (& $ _LINKID, & $ _QUERYID) {</p>
<p>$ this-> mfields = array ();</p>
<p>IF (is_resource ($ _ linkid) && is_resource ($ _ queryid)) {</p>
<p>$ this-> mlinkid = $ _LINKID;</p>
<p>$ this-> mQueryid = $ _QUERYID;</p>
<p>$ this-> mfieldtotal = @Mysql_num_fields ($ this-> mqueryid);</p>
<p>$ this-> mrowtotal = @mysql_num_rows ($ this-> mqueryid);</p>
<p>For ($ I = 0, $ J = $ THIS-> MfieldTotal; $ i <j; $ i   ) {</p>
<p>$ f_name = mysql_field_name ($ this-> MQueryID, $ I);</p>
<p>$ f_type = mysql_field_type ($ this-> MQueryID, $ I);</p>
<p>$ f_len = mysql_field_len ($ this-> MQueryID, $ I);</p>
<p>$ f_f = mysql_field_flags ($ this-> MQueryID, $ I);</p>
<p>$ f_table = mysql_field_table ($ this-> MQueryID, $ I); $ f_f_null = (int) (false === Strpos ($ f_f, 'not_null');</p>
<p>$ f_f_primary_key = (int) (false! == STRPOS ($ f_f, 'primary_key');</p>
<p>$ f_f_unsigned = (int) (false! == STRPOS ($ f_f, 'unsigned');</p>
<p>$ f_f_zerofill = (int) (false! == STRPOS ($ f_f, 'zerofill');</p>
<p>$ f_f_binary = (int) (false! == Strpos ($ f_f, 'binary'));</p>
<p>$ f_f_index = (int) (false! == STRPOS ($ f_f, 'multiple_key');</p>
<p>$ f_f_unique = (int) (false! == STRPOS ($ f_f, 'unique_key');</p>
<p>$ f_f_auto_inc = (int) (false! == STRPOS ($ f_f, 'auto_increment');</p>
<p>$ f_Array = array (</p>
<p>$ f_name,</p>
<p>$ F_TYPE,</p>
<p>$ F_LEN,</p>
<p>$ F_TABLE,</p>
<p>$ F_F_NULL,</p>
<p>$ F_F_PRIMARY_KEY,</p>
<p>$ f_f_index,</p>
<p>$ F_F_UNIQUE,</p>
<p>$ F_F_UNSIGNED,</p>
<p>$ F_F_ZEROFILL,</p>
<p>$ f_f_Auto_inc,</p>
<p>'Name' => $ f_name,</p>
<p>'Type' => $ f_type,</p>
<p>'max_length' => $ f_len,</p>
<p>'Table_in' => $ f_table,</p>
<p>'null' => $ f_f_null,</p>
<p>'primary_key' => $ f_f_primary_key,</p>
<p>'Multiple_key' => $ f_f_index,</p>
<p>'unique_key' => $ f_f_unique,</p>
<p>'unsigned' => $ f_f_unsigned,</p>
<p>'zerofill' => $ f_f_zerofill,</p>
<p>'binary' => $ f_f_binary,</p>
<p>'Auto_Increment' => $ f_f_auto_inc</p>
<p>);</p>
<p>$ this-> mfields [$ I] = $ f_Array;</p>
<p>$ this-> mfields [$ f_name] = $ f_Array;</p>
<p>}</p>
<p>$ this-> movetobegin ();</p>
<p>} else {</p>
<p>$ this-> Error (5);</p>
<p>$ this-> mlinkid = 0;</p>
<p>$ this-> mQueryid = 0;</p>
<p>$ this-> mfieldtotal = 0;</p>
<p>$ this-> MROWTATAL = 0;</p>
<p>$ this-> mpocinter = 0;</p>
<p>}</p>
<p>$ this-> setfetchmode ();</p>
<p>}</p>
<p>/ **</p>
<p>* @ Purpose:</p>
<p>* Set the data set acquisition mode.</p>
<p>* @Method name: setFetchmode ()</p>
<p>* @ Parameters:</p>
<p>* Constant $ _FETCHMODE PHP built-in mysql data set collection mode</p>
<p>* @ Return: Boolean setting success</p>
<p>* /</p>
<p>Function setfetchmode ($ _ fetchmode = mysql_both) {</p>
<p>IF ($ this-> iSerror ()) Return False;</p>
<p>IF ($ _FETCHMODE == mysql_assoc) $ this-> mfetchmode = mysql_assoc;</p>
<p>Else IF ($ _FETCHMODE == mysql_num) $ this-> mfetchmode = mysql_num;</p>
<p>Else $ this-> mfetchmode = mysql_both;</p>
<p>Return True;</p>
<p>}</p>
<p>/ **</p>
<p>* @ Purpose:</p>
<p>* Total number of lines</p>
<p>* @Method Name: Countrows ()</p>
<p>* @ RETURN: INTEGER Total number</p>
<p>* /</p>
<p>Function countrows () {</p>
<p>IF ($ this-> iSerror ()) Return False;</p>
<p>Return $ this-> MROWTAl</p>
<p>}</p>
<p>/ **</p>
<p>* @ Purpose:</p>
<p>* Get the total number of fields</p>
<p>* @Method name: countfields ()</p>
<p>* @ Return: Integer field total</p>
<p>* /</p>
<p>Function countryfields () {</p>
<p>IF ($ this-> iSerror ()) Return False;</p>
<p>RETURN $ THIS-> MfieldTotal</p>
<p>}</p>
<p>/ **</p>
<p>* @ Purpose:</p>
<p>* Clear the search result resources</p>
<p>* @METHOD name: Close ()</p>
<p>* @ Return: Boolean clear success</p>
<p>* /</p>
<p>Function close () {</p>
<p>IF ($ this-> iSerror ()) Return False;</p>
<p>@MYSQL_FREE_RESULT ($ this-> mQueryID);</p>
<p>Return True;</p>
<p>}</p>
<p>/ **</p>
<p>* @ Purpose:</p>
<p>* Get field information</p>
<p>* @Method name: getfieldInfo ()</p>
<p>* @ Parameters:</p>
<p>* Mixed $ _field determine the number or name of the field</p>
<p>* Constant $ _FETCHMODE PHP built-in mysql data set collection mode</p>
<p>* @ RETURN: Mixed field information</p>
<p>* /</p>
<p>Function getfieldInfo ($ _ field = '', $ _FETCHMODE = 8486) {</p>
<p>IF ($ this-> iSerror ()) Return False;</p>
<p>IF ($ this-> mfields [$ _ field]) RETURN FALSE;</p>
<p>IF ($ _FETCHMODE! = mysql_assoc</p>
<p>&& $ _FETCHMODE! = Mysql_num</p>
<p>&& $ _FETCHMODE! = Mysql_both)</p>
<p>$ _FETCHMODE = $ this-> mfetchmode;</p>
<p>$ T_ARR1 = $ this-> mfields [$ _ field];</p>
<p>$ t_ARR2 = array ();</p>
<p>While (List ($ K, $ V) = Each ($ T_ARR1)) {</p>
<p>IF (is_int ($ k)) {</p>
<p>IF ($ _FETCHMODE! = mysql_assoc) $ T_ARR2 [$ K] = $ V;} else {</p>
<p>IF ($ _FETCHMODE! = mysql_num) $ T_ARR2 [$ K] = $ V;</p>
<p>}</p>
<p>}</p>
<p>Return $ T_ARR2;</p>
<p>}</p>
<p>/ **</p>
<p>* @ Purpose:</p>
<p>* Set the pointer position.</p>
<p>* @METHOD name: moveto ()</p>
<p>* @ Parameters:</p>
<p>* Integer $ _POINTER new pointer position</p>
<p>* @ RETURN: Boolean settings have been successful</p>
<p>* /</p>
<p>Function moveto ($ _ POINTER = 1) {</p>
<p>IF ($ this-> iSerror ()) Return False;</p>
<p>IF (! is_int ($ _ POINTER)) $ _POINTER = INTVAL ($ _ Pointer);</p>
<p>IF ($ _POINTER <1 | $ _POINTER> $ this-> mrowtotal) $ _POINTER = 1;</p>
<p>IF (! $ this-> mrowtotal) {</p>
<p>$ this-> mpocinter = 0;</p>
<p>Return False;</p>
<p>} else if (! @Mysql_data_seek ($ this-> mqueryid, $ _POINTER - 1)) {</p>
<p>Return $ this-> Error (6);</p>
<p>}</p>
<p>$ this-> mrowdata = mysql_fetch_array ($ this-> mqueryid, mysql_both);</p>
<p>$ this-> mpocinter = $ _POINTER;</p>
<p>Return True;</p>
<p>}</p>
<p>/ **</p>
<p>* @ Purpose:</p>
<p>* Offset pointer position.</p>
<p>* @Method name: moveby ()</p>
<p>* @ Parameters:</p>
<p>* Integer $ _POINTER The offset of the pointer position</p>
<p>* @ RETURN: Boolean settings have been successful</p>
<p>* /</p>
<p>Function Moveby ($ _ POINTER = 1) {</p>
<p>IF ($ this-> iSerror ()) Return False;</p>
<p>IF (! is_int ($ _ POINTER)) $ _POINTER = INTVAL ($ _ Pointer);</p>
<p>$ _POINTER   = $ this-> mpoc;</p>
<p>Return $ this-> MoveTo ($ _ Pointer);</p>
<p>}</p>
<p>/ **</p>
<p>* @ Purpose:</p>
<p>* Offset pointer position to initial.</p>
<p>* @Method name: movetobegin ()</p>
<p>* @ RETURN: Boolean settings have been successful</p>
<p>* /</p>
<p>Function movetobegin () {</p>
<p>IF ($ this-> iSerror ()) Return False;</p>
<p>Return $ this-> Moveto ();</p>
<p>}</p>
<p>/ **</p>
<p>* @ Purpose:</p>
<p>* Offset pointer position to the end.</p>
<p>* @METHOD name: movetoend ()</p>
<p>* @ RETURN: Boolean settings have been successful</p>
<p>* /</p>
<p>Function movetoeend () {</p>
<p>IF ($ this-> iSerror ()) Return False;</p>
<p>Return $ this-> MoveTo ($ this-> MROWTOT);</p>
<p>}</p>
<p>/ **</p>
<p>* @ Purpose:</p>
<p>* Get the array form of the pointer position data set</p>
<p>* @METHOD name: getArray ()</p>
<p>* @ Parameters:</p>
<p>* constant $ _FETCHMODE PHP built-in mysql dataset collection mode * @ Return: Mixed data array</p>
<p>* /</p>
<p>Function GetArray ($ _ fetchmode = 8486) {</p>
<p>IF ($ this-> iSerror ()) Return False;</p>
<p>IF ($ _FETCHMODE! = mysql_assoc</p>
<p>&& $ _FETCHMODE! = Mysql_num</p>
<p>&& $ _FETCHMODE! = Mysql_both)</p>
<p>$ _FETCHMODE = $ this-> mfetchmode;</p>
<p>$ t_ARR = array ();</p>
<p>While (List ($ K, $ V) = Each ($ this-> mrowdata) {</p>
<p>IF (is_int ($ k)) {</p>
<p>IF ($ _FETCHMODE! = mysql_assoc) $ T_ARR [$ K] = $ V;</p>
<p>} else {</p>
<p>IF ($ _FETCHMODE! = mysql_num) $ T_ARR [$ K] = $ V;</p>
<p>}</p>
<p>}</p>
<p>Return $ T_ARR;</p>
<p>}</p>
<p>/ **</p>
<p>* @ Purpose:</p>
<p>* Get object form data of the pointer position data set</p>
<p>* @Method name: getObject ()</p>
<p>* @ RETURN: Mixed data object</p>
<p>* /</p>
<p>Function & getObject () {</p>
<p>IF ($ this-> iSerror ()) Return False;</p>
<p>While (List ($ K, $ V) = Each ($ this-> mrowdata) {</p>
<p>IF (is_int ($ k)) {</p>
<p>$ T_OBJ -> $ K = $ V;</p>
<p>}</p>
<p>}</p>
<p>Return $ T_OBJ;</p>
<p>}</p>
<p>/ **</p>
<p>* @ Purpose:</p>
<p>* Get the specified field data of the pointer position dataset</p>
<p>* @Method name: getfield ()</p>
<p>* @ Parameters:</p>
<p>* Mixed $ _field determine the number or name of the field</p>
<p>* @ RETURN: Mixed field information</p>
<p>* /</p>
<p>Function GetField ($ _ field = '') {</p>
<p>IF ($ this-> iSerror ()) Return False;</p>
<p>IF (! isset ($ tris-> Mrowdata) Return False;</p>
<p>Return $ this-> Mrowdata [$ _ field];</p>
<p>}</p>
<p>/ *</p>
<p>* @ Purpose:</p>
<p>* Judging whether it starts in retrieving data sets</p>
<p>* @Method name: atbegin ()</p>
<p>* @ RETURN: BOOLEAN is at the beginning</p>
<p>* /</p>
<p>Function atbegin () {</p>
<p>IF ($ this-> iSerror ()) Return False;</p>
<p>Return ($ this-> MROWTATAL && $ this-> mpoint == 1);</p>
<p>}</p>
<p>/ *</p>
<p>* @ Purpose:</p>
<p>* Judging whether it is the last end of the retrieval data set</p>
<p>* @METHOD name: atend ()</p>
<p>* @ RETURN: BOOLEAN is at the end</p>
<p>* /</p>
<p>Function atend () {</p>
<p>IF ($ this-> iSerror ()) Return False;</p>
<p>Return ($ this-> MROWTAAL && $ this-> mpoint == $ this-> mrowtotal);</p>
<p>}</p>
<p>}</p>
<p>/ ** class package end * /</p>
<p>}</p>
<p>?></p></div><div class= 转载请注明原文地址:https://www.9cbs.com/read-112259.html


New Post(0)