php中mysql模块部分功能的简单封装
作者:bea
代码如下: 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('localh
代码如下:
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 );
}
}
这样做看起来就只对可移植有用,其它的作用还体会不到
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- 30 个很棒的PHP开源CMS内容管理系统小结
- 比较简单实用的PHP无限分类源码分享(思路不错)
- php 错误处理经验分享
- php购物车实现代码
- 使用PHP实现密保卡功能实现代码<打包下载直接运行>
- PHP实现时间轴函数代码
- PHP+Mysql+jQuery实现动态展示信息
- PHP+Mysql+jQuery实现发布微博程序 jQuery篇
- php实现用户在线时间统计详解
- php 文件缓存函数
- php数字转汉字代码(算法)
- PHP判断远程url是否有效的几种方法小结
- php下利用curl判断远程文件是否存在的实现代码
- PHP下判断网址是否有效的代码
- Admin generator, filters and I18n
- 如何在symfony中导出为CSV文件中的数据
- php中时间轴开发(刚刚、5分钟前、昨天10:23等)
- linux iconv方法的使用
- linux系统上支持php的 iconv()函数的方法