php中mysql模块部分功能的简单封装
更新时间:2011年09月30日 23:51:22 作者:
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 );
}
}
这样做看起来就只对可移植有用,其它的作用还体会不到
相关文章
解决php使用异步调用获取数据时出现(错误c00ce56e导致此项操作无法完成)
本篇文章是对php中使用异步调用获取数据时出现(由于出现错误c00ce56e而导致此项操作无法完成)的解决方法进行了详细的分析介绍,需要的朋友参考下2013-07-07session在php5.3中的变化 session_is_registered() is deprecated in
在php 5.3中session_is_registered()已经是放弃使用了,大家在使用过程中需要注意一下了2013-11-11
最新评论