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的存储过程的实现代码

MySQL好像从5.0开始才引入存储过程,反正以前做应用的时候从没碰过,不过现在因为主要作内部系统,所以很多应用都用到了存储过程,当然前台有时候也需要调用MySQL存储过程,PHP的My...

php mysql数据库操作分页类

复制代码 代码如下:<?php /*  *    mysql数据库 分页类  *  &nb...

php写的带缓存数据功能的mysqli类

复制代码 代码如下: <?php /** * Mysqli类 */ class db_mysqli { protected $mysqli; protected $sql; pro...

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

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

php+mysql+jquery实现简易的检索自动补全提示功能

php+mysql+jquery实现简易的检索自动补全提示功能

本文实例讲述了php+mysql+jquery实现简易的检索自动补全提示功能。分享给大家供大家参考,具体如下: 这段时间看了一些关于自动补全提示方面的内容,发现大部分实现过程都十分复杂。...