手机
当前位置:查字典教程网 >编程开发 >php教程 >php中mysql模块部分功能的简单封装
php中mysql模块部分功能的简单封装
摘要:复制代码代码如下:classmysql{private$db;//datebaseconnectprivate$result;//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 );

}

}

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

【php中mysql模块部分功能的简单封装】相关文章:

php分页的功能模块分享

php中PDO方式实现数据库的增删改查

php实现的简单日志写入函数

PHP中显示格式化的用户输入

php结合ACCESS的跨库查询功能

一个程序下载的管理程序(四)

php中文件上传的安全问题

PHP中的traits简单使用实例

php基于curl扩展制作跨平台的restfule 接口

一个用php3编写的简单计数器

精品推荐
分类导航