手机
当前位置:查字典教程网 >编程开发 >php教程 >php中mysql模块部分功能的简单封装
php中mysql模块部分功能的简单封装
摘要:复制代码代码如下:classmysql{private$db;//datebaseconnectprivate$result;//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分页函数

php中smarty变量修饰用法实例分析

php 字母大小写转换的方法

php支持中文字符串分割的函数

通过对php一些服务器端特性的配置加强php的安全

php中file_exists函数使用详解

phpmyadmin 数据库导入2048kb的解决办法

php调整服务器时间的方法

Php部分常见问题总结第1/2页

php输出全球各个时区列表的方法

精品推荐
分类导航