php中mysql模块部分功能的简单封装

yipeiwu_com4年前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简单备份与还原MySql的方法。分享给大家供大家参考,具体如下: 一、备份: <?php header ( "content-Type: text/...

php将csv文件导入到mysql数据库的方法

本文实例讲述了php将csv文件导入到mysql数据库的方法。分享给大家供大家参考。具体分析如下: 本程序实现数据导入原理是先把csv文件上传到服务器,然后再通过php的fopen与fg...

PHP mysql事务问题实例分析

本文实例分析了PHP的mysql事务问题。分享给大家供大家参考,具体如下: 对于myisam数据库,可以控制事务的进行: $mysqlrl = mysql_connect ( $db...

mysql总结之explain

mysql总结之explain

explain主要用于sql语句中的select查询,可以显示的查看该sql语句索引的命中情况,从而更好的利用索引、优化查询效率。     Explain语...

php实现mysql数据库连接操作及用户管理

文件列表。。文件内容。。 dbconn.php userListt.php editUser.php editDo.php detailUser.php deleteUser.php a...