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

yipeiwu_com6年前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实现PDO操作mysql存储过程示例

本文实例讲述了PHP实现PDO操作mysql存储过程。分享给大家供大家参考,具体如下: 一 代码 sql语句: create procedure pro_reg (in nc var...

简单介绍win7下搭建apache+php+mysql开发环境

环境目录:E:\dev​ 一、Apache 下载地址:http://www.apachelounge.com/download/​ 我们下载VC11运行库的 1....

php环境配置 php5 mysql5 apache2 phpmyadmin安装与配置

php环境配置 php5 mysql5 apache2 phpmyadmin安装与配置

php环境的配置,对于新手来说,绝对是一件烦事。总会遇到这样那样的问题,走很多弯路。所以今天特意写了这个配置文档,相信按照以下步骤你一定会成功的。错误的地方也希望各位指正。 更多文章 p...

在php和MySql中计算时间差的方法

最近在研究自己爱围脖的时候就要计算到恋爱天数,这需要php根据每天的日期进行计算,下面就来谈谈实现这种日期计算的几种方法: (1) 如果有数据库就很容易了!若是MSSQL可以使用触发器!...

php mysql procedure实现获取多个结果集的方法【基于thinkPHP】

本文实例讲述了php mysql procedure实现获取多个结果集的方法。分享给大家供大家参考,具体如下: protected function getRs($id) {...