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

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

相关文章

Win2003下APACHE+PHP5+MYSQL4+PHPMYADMIN 的简易安装配置

先从各官方网站下了APACHE2.050、PHP5、MYSQL4.0.20、PHPMYADMIN2.57  apache_2.0.50-win32-x86-no_ssl.msi...

让你的WINDOWS同时支持MYSQL4,MYSQL4.1,MYSQL5X

让你的WINDOWS同时支持MYSQL4,MYSQL4.1,MYSQL5X

作为一名PHP+MYSQL(其它数据库)程序员,你可能为了满足不同的需求,而需要在不同的数据库版本的环境中进行测试 但正常的安装MYSQL,windows系统中只能存在一个版本的MYSQ...

PHP 使用MySQL管理Session的回调函数详解

复制代码 代码如下:<?php class MySession extends DBSQL {  /**   * __constr...

php调用mysql存储过程实例分析

本文实例分析了php调用mysql存储过程的方法。分享给大家供大家参考。具体分析如下: Mysql存储过程创建语法,代码如下: CREATE PROCEDURE和CREATE FUNCT...

PHP数据库操作之基于Mysqli的数据库操作类库

此类库简单、易用,便于你自己修改和对功能的改善,能解决大部分 PHP 项目中执行的 SQL 操作。 初步工作 首先,请大家下载这个类库 M.class.php 再下载一个 My...