php中mysql模块部分功能的简单封装

<div class="codetitle"><a style="CURSOR: pointer" data="97524" class="copybut" id="copybut97524" onclick="doCopy('code97524')"> 代码如下:

<div class="codebody" id="code97524">
class MysqL
{
private $db; // datebase connect
private $result; // MysqL result
static private $MysqL; // MysqL object
private function __construct()
{ // The work before Create an object
$this->db = MysqL_connect('localhost','root','');
MysqL_select_db('hello',$this->db );
}
public static function getobject()
{ //if have a object,return that object,Not create
if(! self::$MysqL instanceof self)
self::$MysqL = new self;
return self::$MysqL;
}
public function query($sql)
{
$this->result = MysqL_query($sql,$this->db);
return $this->result;
}
public function fetch()
{
if( isset($this->result ) )
return MysqL_fetch_assoc( $this->result );
}
public function error()
{
return 'error:'.MysqL_error();
}
public function num() // for sql select result
{
return MysqL_num_rows( $this->result );
}
public function close()
{ // return true or false
return MysqL_close( $this->db );
}
}

这样做看起来就只对可移植有用,其它的作用还体会不到

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...