电脑安全

您当前的位置:主页 > 电脑安全 >

php class的申明与使用方法-网络编程

来源:[db:来源]标题:   数据库    编辑:电脑技术全能网 时间:2019-09-22 12:30

原标题:php class的申明与使用方法-网络编程
   上面来看看在许多顺序言语中会应用到的class吧,当初会举个简略的实例来完成php class,类声名,class应用方式哦。 <?php/** Explorer! 函数库* 编写日期:2008-06-29* 最初更新:2008-07-18 2:08**/class System{//体系局部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){//猎取体系信息$SQL = new MySQL();$SQL->Query("SELECT * FROM `sysinfo`;");$SQL->NextRecord();$TMP = $SQL->GetRecord($Name);$SQL->Free();return $TMP;}function find_member($name){//查找该用户(注册时须要)$SQL = New MySQL();$SQL->Query("SELECT * FROM `members` WHERE `username` = '$name';");$RS = $SQL->RowS();$SQL->Free();if($RS)return 1;elsereturn 0;}function str_safe($str){//字符串保险过滤$str = str_replace($str,";",";");$str = str_replace($str,"'","‘");$str = str_replace($str,"/","/");$str = str_replace($str,"`","`");$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{//数据库局部var $DBServer = 'localhost';//效劳器var $DBName = '';//数据库称号var $DBUser = '';//数据库用户var $DBPass = '';//数据库暗码var $OnErrorResume = 1;//过错提醒封闭var $LinkID = 0;//衔接句柄var $QueryID = 0;//查问句柄var $ResultS = array();//查问成果集var $Error = '';//过错信息function Connect($Srv = "",$Usr = "",$Pass = "",$DB = ""){//衔接数据库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("数据库衔接失利,请接洽治理员修复此成绩。");}@mysql_select_db($DB,$this->LinkID) or die("数据库抉择失利,请接洽治理员修复此成绩。");return $this->LinkID;}function Free(){//开释查问成果@mysql_free_result($this->QueryID);$this->QueryID = 0;}function RowS(){//查问到的记载总数if(!$this->QueryID) return 0;return @mysql_num_rows($this->QueryID);}function NextRecord(){//下一笔记录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){//履行查问if($Sql == "") return 0;if($this->LinkID == 0) $this->Connect();if($this->QueryID) $this->Free();//开释本来查问成果$this->QueryID = @mysql_query($Sql,$this->LinkID);$this->Error = mysql_error($this->LinkID);if(!$this->QueryID) exit("$Sql履行失利.");return $this->QueryID;}function GetRecord($Name){if(!$this->QueryID) return 0;return $this->ResultS[$Name];}}?>

上一篇:在php中配置使用smarty模板引擎-网络编程

下一篇:没有了