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

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

相关文章

win7+apache+php+mysql环境配置操作详解

1.php版本简介php各版本之间的区别,php版本后面一般有VC6和VC9、Thread Safe和Non Thread Safe的区别,VC6就是legacy Visual Stud...

php往mysql中批量插入数据实例教程

前言 假如说我有这样一个表,我想往这个表里面插入大量数据 CREATE TABLE IF NOT EXISTS `user_info` ( `id` int(11) NOT NUL...

flash+php+mysql打造简单留言本教程第1/3页

flash+php+mysql打造简单留言本教程第1/3页

(主要参考了火山的帖子:★FLASH与ASP通信入门教程——做真正属于自己的留言本!)。网上没有比较好的php留言本相关教程,我下载的N多源文件都看得云里雾里,而且好多都将代码写在MC上...

mysql5的sql文件导入到mysql4的方法

1、将mysql5里导出的sql文件导入到mysql5中。 2、用mysqldump -uroot -p1234 --opt --compatible=mysql40 -A -re:\l...

Windows下IIS6/Apache2.2.4+MySQL5.2+PHP5.2.1安装配置方法

03年的时候就看过一本php的书,那时还是php3,回首四年php的在web开的的前景真还是一片光明啊!三年不见的php在去看已到了php5了,现在算起我真正从写第一个php的WEB开始...