php中mysql模块部分功能的简单封装
2015-01-24信息快讯网
php中mysql模块部分功能的简单封装,很多cms都是封装了一些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 );
}
}
这样做看起来就只对可移植有用,其它的作用还体会不到
基于MySQL体系结构的分析
Mysql中分页查询的两个解决方法比较
记录mysql性能查询过程的使用方法
基于MySQL分区性能的详细介绍
PHP执行批量mysql语句的解决方法
PHP面向对象三大特点学习(充分理解抽象、封装、继承、多态)
linux系统上支持php的 iconv()函数的方法
php XMLWriter类的简单示例代码(RSS输出)
PHP+MYSQL会员系统的登陆即权限判断实现代码
PHP与SQL注入攻击防范小技巧
PHP正确配置mysql(apache环境)
PHP MySQL应用中使用XOR运算加密算法分享
php中将图片gif,jpg或mysql longblob或blob字段值转换成16进制字符串
PHP FOR MYSQL 代码生成助手(根据Mysql里的字段自动生成类文件的)
一个PHP验证码类代码分享(已封装成类)
php学习笔记 php中面向对象三大特性之一[封装性]的应用
重新封装zend_soap实现http连接安全认证的php代码
PHP访问MYSQL数据库封装类(附函数说明)
php下封装较好的数字分页方法