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 mysqli查询语句返回值类型实例分析

本文实例分析了php mysqli查询语句返回值类型。分享给大家供大家参考,具体如下: <?php $link = new mysqli('localhost', 'r...

php+mysql数据库实现无限分类的方法

本文实例讲述了php+mysql数据库实现无限分类的方法。分享给大家供大家参考。具体分析如下: 这款php无限分类代码比较完整理包括了数据库是mysql的,有增加、删除、编辑、移动的功能...

用phpmyadmin更改mysql5.0登录密码

update mysql.user set password=old_password('新密码') where user='用户名'&...

PHP使用PDO创建MySQL数据库、表及插入多条数据操作示例

本文实例讲述了PHP使用PDO创建MySQL数据库、表及插入多条数据操作。分享给大家供大家参考,具体如下: 创建 MySQL 数据库: <?php $servernam...

PHP无法访问远程mysql的问题分析及解决

首先说明,远程服务器是可远程访问的。 我遇到的问题是这样的:有A,B,C三台服务器,C为服务器,B可以用PHP成功连接上C机器的mysql,而A机器则不能连接! 可以说,肯定不是代码有什...