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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

  2021-03-18 我要评论
想了解php中mysql模块部分功能的简单封装的相关内容吗,在本文为您仔细讲解mysql模块的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:mysql模块,下面大家一起来学习吧。
复制代码 代码如下:

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 );
}
}

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

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们