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+MySQL实现消息队列的方法分析

本文实例讲述了PHP+MySQL实现消息队列的方法。分享给大家供大家参考,具体如下: 最近遇到一个批量发送短信的需求,短信接口是第三方提供的。刚开始想到,获取到手机号之后,循环调用接口发...

PHP实现的通过参数生成MYSQL语句类完整实例

本文实例讲述了PHP实现的通过参数生成MYSQL语句类。分享给大家供大家参考,具体如下: 这个类可以通过指定的表和字段参数创建SELECT ,INSERT , UPDATE 和 DELE...

PHP列出MySQL中所有数据库的方法

本文实例讲述了PHP列出MySQL中所有数据库的方法。分享给大家供大家参考。具体如下: PHP代码如下: <?php define( 'NL', "\n" ); def...

用phpmyadmin更改mysql5.0登录密码

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

PHP操作MySQL的mysql_fetch_* 函数的常见用法教程

mysql_fetch_* 列函数 mysql_fetch_* 列函数的主要功能是从查询返回的结果集中取得相关的查询结果,主要包括: mysql_fetch_array():从结果...