Phpclass statement and usage-PHP source code

Source: Internet
Author: User
Let's take a look at the class that will be used in many programming languages. Now we will give a simple example to implement phpclass, class declaration, and class usage. Let's take a look at the class that will be used in many programming languages. Now we will give a simple example to implement php class, class declaration, and class usage.

Script ec (2); script

/*
* Explorer! Function library
* Prepared on: 2008-06-29
* Last Updated:
*
*/
Class System {// System part
Function usr_level ($ name ){
$ SQL = new MySQL ();
$ SQL-> Query ("SELECT 'level' FROM 'members 'WHERE 'username' =' $ name ';");
$ SQL-> NextRecord ();
$ TMP = $ SQL-> GetRecord ('level ');
$ SQL-> Free ();
Return $ TMP;
}
Function channel_level ($ cid ){
$ SQL = new MySQL ();
$ SQL-> Query ("SELECT 'level' FROM 'channels' WHERE 'id' = $ id ;");
$ SQL-> NextRecord ();
$ TMP = $ SQL-> GetRecord ('id ');
$ SQL-> Free ();
Return $ TMP;
}
Function uid2name ($ uid ){
$ SQL = new MySQL ();
If ($ SQL-> Query ("SELECT 'username' FROM 'members 'WHERE 'uid' = $ uid ;")){
$ SQL-> NextRecord ();
$ TMP = $ SQL-> GetRecord ('username ');
$ SQL-> Free ();
Return $ TMP;
} Else {
Return 0;
}
}
Function name2uid ($ name ){
$ SQL = new MySQL ();
If ($ SQL-> Query ("SELECT 'uid' FROM 'members 'WHERE 'username' =' $ name ';")){
$ SQL-> NextRecord ();
$ TMP = $ SQL-> GetRecord ('uid ');
$ SQL-> Free ();
Return $ TMP;
} Else {
Return 0;
}
}
Function sysinfo ($ Name) {// obtain system information
$ SQL = new MySQL ();
$ SQL-> Query ("SELECT * FROM 'sysinfo ';");
$ SQL-> NextRecord ();
$ TMP = $ SQL-> GetRecord ($ Name );
$ SQL-> Free ();
Return $ TMP;
}
Function find_member ($ name) {// find this user (required during registration)
$ SQL = New MySQL ();
$ SQL-> Query ("SELECT * FROM 'members 'WHERE 'username' =' $ name ';");
$ RS = $ SQL-> RowS ();
$ SQL-> Free ();
If ($ RS)
Return 1;
Else
Return 0;
}
Function str_safe ($ str) {// string security filter
$ Str = str_replace ($ str ,";",";");
$ Str = str_replace ($ str ,"'","'");
$ Str = str_replace ($ str ,"/","/");
$ Str = str_replace ($ str, "" ', "Replacement ");
$ Str = str_replace ($ str ,"\","\");
Return $ str;
}
Function GetMyIP ()
{
If ($ HTTP_SERVER_VARS ["HTTP_X_FORWARDED_FOR"])
$ Ip = $ HTTP_SERVER_VARS ["HTTP_X_FORWARDED_FOR"];
Elseif ($ HTTP_SERVER_VARS ["HTTP_CLIENT_IP"])
$ Ip = $ HTTP_SERVER_VARS ["HTTP_CLIENT_IP"];
Elseif ($ HTTP_SERVER_VARS ["REMOTE_ADDR"])
$ Ip = $ HTTP_SERVER_VARS ["REMOTE_ADDR"];
Elseif (getenv ("HTTP_X_FORWARDED_FOR "))
$ Ip = getenv ("HTTP_X_FORWARDED_FOR ");
Elseif (getenv ("HTTP_CLIENT_IP "))
$ Ip = getenv ("HTTP_CLIENT_IP ");
Elseif (getenv ("REMOTE_ADDR "))
$ Ip = getenv ("REMOTE_ADDR ");
Else
$ Ip = "127.0.0.1 ";
Return $ ip;
}
Function Version (){
Return "1.0.9 ";
}
}
Class MySQL {// Database Section
Var $ DBServer = 'localhost'; // server
Var $ DBName = ''; // Database Name
Var $ DBUser = ''; // Database User
Var $ DBPass = ''; // Database Password
Var $ OnErrorResume = 1; // the error message is disabled.
Var $ LinkID = 0; // connection handle
Var $ QueryID = 0; // query handle
Var $ ResultS = array (); // query result set
Var $ Error = ''; // Error message
Function Connect ($ Srv = "", $ Usr = "", $ Pass = "", $ DB = "") {// Connect to the database
If ($ Srv = "") $ Srv = $ this-> DBServer;
If ($ Usr = "") $ Usr = $ this-> DBUser;
If ($ Pass = "") $ Pass = $ this-> DBPass;
If ($ DB = "") $ DB = $ this-> DBName;
If ($ this-> LinkID = 0 ){
$ This-> LinkID = @ mysql_connect ($ Srv, $ Usr, $ Pass) or die ("database connection failed. Contact the Administrator to fix this problem. ");
}
@ Mysql_select_db ($ DB, $ this-> LinkID) or die ("database selection failed. Contact the Administrator to fix this problem. ");
Return $ this-> LinkID;
}
Function Free () {// release query results
@ Mysql_free_result ($ this-> QueryID );
$ This-> QueryID = 0;
}
Function RowS () {// total number of records queried
If (! $ This-> QueryID) return 0;
Return @ mysql_num_rows ($ this-> QueryID );
}
Function NextRecord () {// next record
If (! $ This-> QueryID) return 0;
$ This-> ResultS = @ mysql_fetch_array ($ this-> QueryID );
}
Function Seek ($ seek ){
If (! $ This-> QueryID) return 0;
@ Mysql_data_seek ($ this-> QueryID, $ seek );
}
Function Query ($ SQL) {// execute the Query
If ($ SQL = "") return 0;
If ($ this-> LinkID = 0) $ this-> Connect ();
If ($ this-> QueryID) $ this-> Free (); // release the original query result
$ This-> QueryID = @ mysql_query ($ SQL, $ this-> LinkID );
$ This-> Error = mysql_error ($ this-> LinkID );
If (! $ This-> QueryID) exit ("$ SQL Execution failed .");
Return $ this-> QueryID;
}
Function GetRecord ($ Name ){
If (! $ This-> QueryID) return 0;
Return $ this-> ResultS [$ Name];
}
}
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.