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;

}

}

}

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值