php中mysql模块部分功能的简单封装

yipeiwu_com5年前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数据到csv文件的方法

本文实例讲述了php使用指定编码导出mysql数据到csv文件的方法。分享给大家供大家参考。具体实现方法如下: <?php /* * PHP code to expo...

win7 64位系统 配置php最新版开发环境(php+Apache+mysql)

一 :准备阶段 1:php php-5.5.13下载链接:http://windows.php.net/downloads/releases/php-5.5.13-Win32-VC11-...

php+mysqli使用预处理技术进行数据库查询的方法

本文实例讲述了php+mysqli使用预处理技术进行数据库查询的方法。分享给大家供大家参考。具体如下: 代码有些难度,需要基础知识比较扎实才能好理解,代码先放上来: 这里实现查询所有 i...

用mysql内存表来代替php session的类

复制代码 代码如下:<?php /** @Usage: use some other storage method(mysql or memcache) instead of ph...

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

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