电脑安全

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

php 数据查询与连接类-网络编程

来源:[db:来源]标题:   数据查询    编辑:电脑技术全能网 时间:2019-09-20 12:29

原标题:php 数据查询与连接类-网络编程
   php 数据查问与衔接类<?php/*** Class program for yinghua05-2* designer :songsong*/class MySQL {var $link;var $result;var $querys;function MySQL($host = '', $user = '', $pw = '', $db = '', $encode = 'UTF8') {$this->querys = 0;if($host != '' && $user != '' && $db != '') {$this->connect($host,$user,$pw,$db,$encode);}}/** * connect to database * * @param unknown_type $host * @param unknown_type $user * @param unknown_type $pw * @param unknown_type $db * @return boolean */function connect($host,$user,$pw,$db,$encode = 'UTF8') {$resource = mysql_connect($host,$user,$pw);if(is_resource($resource)) {$this->link = $resource;if(mysql_select_db($db,$this->link)) {unset($resource);if (floatval(mysql_get_server_info($this->link)) > 4.1 && isset($encode)) {mysql_query('SET NAMES "'.$encode.'"');}return true;} else {unset($resource);return false;}} else {unset($resource);return false;}}/** * query sql * * @param unknown_type $query * @return unknown */function query($query) {$result = mysql_query($query,$this->link);$this->querys ++;if($result) {$this->result = $result;return true;} else {return false;}}/** * fetch a row * * @return mixed */function fetch() {if(is_resource($this->result)) {return mysql_fetch_array($this->result);} else {return false;}}/** * fetch all result * * @return mixed */function fetchAll() {if(is_resource($this->result)) {$temp = array();while ($row = mysql_fetch_array($this->result)) {$temp[] = $row;}return $temp;} else {return false;}}/** * return the querys * * @return integer */function getQuerys() {return $this->querys;}/** * get the numbers of the result * * @return int */function getNumberRow() {if (is_resource($this->result)) {return mysql_num_rows($this->result);} else {return 0;}}/** * free result * * @return boolean */function free() {if(is_resource($this->result)) {mysql_free_result($this->result);return true;} else {return false;}}/** * close mysql connect * * @return boolean */function close() {if(is_resource($this->link)) {mysql_close($this->link);return true;} else {return false;}}}?>

上一篇:php的mail()函数出错的问题-网络编程

下一篇:没有了