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

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

相关文章

Mysql的Root密码忘记,查看或修改的解决方法(图文介绍)

Mysql的Root密码忘记,查看或修改的解决方法(图文介绍)

首先启动命令行 1.在命令行运行:taskkill /f /im mysqld-nt.exe 下面的操作是操作mysql中bin目录下的一些程序,如果没有配置环境变量的话,需要切换到...

PHP+Mysql+jQuery实现发布微博程序 jQuery篇

PHP+Mysql+jQuery实现发布微博程序 jQuery篇

该应用实现了即时统计输入字数,并且通过ajax与后台交互,将输入内容插入到话题列表中。我将整个流程分为两部分,本文讲解第一部分jquery实现前端交互操作。 首先查看示例:DEMO X...

PHP递归写入MySQL实现无限级分类数据操作示例

本文实例讲述了PHP递归写入MySQL实现无限级分类数据操作。分享给大家供大家参考,具体如下: PHP递归写入MySQL无限级分类数据,表结构: CREATE TABLE `kepl...

php MySQL与分页效率

 最基本的分页方式: SELECT ... FROM ... WHERE ... ORDER BY&nbs...

php操作mysql获取select 结果的几种方法

如果用了 MYSQL_BOTH,将得到一个同时包含关联和数字索引的数组。 用 MYSQL_ASSOC 只得到关联索引(如同mysql_fetch_assoc() 那样), 用 MYSQL...