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

前端之家收集整理的这篇文章主要介绍了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 );
}
}

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

猜你在找的PHP相关文章