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

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

相关文章

IIS下配置Php+Mysql+zend的图文教程

IIS下配置Php+Mysql+zend的图文教程

  为了迎接dvphp公测,特发此教程,希望对一些不会的朋友有所帮助,希望会的朋友多多指教!   下面的教程都是在windows 2000下实现的,其他系统请自己参...

解析阿里云ubuntu12.04环境下配置Apache+PHP+PHPmyadmin+MYsql

此教程中使用的相关IP等设置,在你的环境中要做相应修改。使用之前更新apt-get,因为服务器基本上是一个裸系统apt-get update;apt-get upgrade;1 我们使用...

php使用mysqli和pdo扩展,测试对比连接mysql数据库的效率完整示例

php使用mysqli和pdo扩展,测试对比连接mysql数据库的效率完整示例

本文实例讲述了php使用mysqli和pdo扩展,测试对比连接mysql数据库的效率。分享给大家供大家参考,具体如下: <?php /** * 测试pdo和mysql...

解析php session_set_save_handler 函数的用法(mysql)

复制代码 代码如下:<?php /*============================文件说明========================================...

php+mysql实现的二级联动菜单效果详解

本文实例讲述了php+mysql实现的二级联动菜单效果。分享给大家供大家参考,具体如下: <!--php+mysql二级联动--> <html> <he...