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

yipeiwu_com5年前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 );
}
}

这样做看起来就只对可移植有用,其它的作用还体会不到

相关文章

DW中链接mysql数据库时,建立字符集中文出现乱码的解决方法

只是中文出现乱码时,在链接数据库后面,加上这一句 utf8的话 mysql_query("SET NAMES 'utf8'"); gbk的话 mysql_query("SET NAMES...

mysql limit查询优化分析

Limit语法: 复制代码 代码如下:SELECT * FROM table LIMIT [offset,] rows | rows OFFSET offset LIMIT子句可以被用于...

MySQL连接数超过限制的解决方法

max_user_connections 是 MySQL 用户连接数的最大值设置,整段语句的意思是:服务器的 MySQL 的最大连接数参数设置不足。解决方法:修改 MySQL 安装目录下...

将IP地址转换为整型数字的PHP方法、Asp方法和MsSQL方法、MySQL方法

首先我们要先了解一下IP地址转换为整型(严格来说应该说是长整型)的原理~ 【转换原理】:假设IP为:w.x.y.z,则IP地址转为整型数字的计算公式为:intIP = 256*256*2...

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

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