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

yipeiwu_com6年前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 将excel导入mysql

这里介绍一个直接将excel文件导入mysql的例子。我花了一晚上的时间测试,无论导入简繁体都不会出现乱码,非常好用。PHP-ExcelReader,下载地址: http://sourc...

php实现mysql连接池效果实现代码

循环从mysql连接池中获取连接,不需要重复创建新的连接。 参考配置修改:可以参考下面的文章 防止访问量过大,把连接数占满了 <?php /** * @author...

发款php蜘蛛统计插件只要有mysql就可用

于是昨天便认真的做了一下,功能多一点,可以对各种搜索引擎统计分析。可以在多个时间段进行查看。其实代码很简单,为了更简洁些,代码压缩到6k.分为6个文件 1.安装程序 spilder_in...

PHP程序员最常犯的11个MySQL错误小结

对于很多新手们来说,使用PHP可以在短短几个小时之内轻松地写出具有特定功能的代码。但是,构建一个稳定可靠的数据库却需要花上一些时日和相关技能。下面列举了我曾经犯过的最严重的11个MySQ...

apache+php+mysql安装配置方法小结

apache+php+mysql安装配置方法小结

整个安装流程如下: 1,首先安装apache:我安装的版本是: httpd-2.2.16-win32-x86-openssl-0.9.8o.msi 网址:http://www.apach...