Chinaunix首页 | 论坛 | 博客
  • 博客访问: 247701
  • 博文数量: 76
  • 博客积分: 1410
  • 博客等级: 上尉
  • 技术积分: 745
  • 用 户 组: 普通用户
  • 注册时间: 2009-10-28 16:04
文章分类

全部博文(76)

文章存档

2013年(2)

2010年(21)

2009年(53)

我的朋友

分类:

2009-10-29 16:46:16

    class Conn_DB{
        var
$severname = "用户名";
//
        
var $dbname = "数据库名";
//
        
var $username ="帐号";
//
        
var $password ="密码";
//
        
var $link_id;
//
        
var $num_rows;
//
        
var $query_id;
//
        
var $affected_rows;
//
        
var $insertid;
//
        
function Conn_DB(){
#$servername,$dbname,$username,$password
            
$this -> link_id = @mysql_connect($severname,$username,$password) or die ($this-> link_id = "Link Server Error!"
);
            
$this -> link_id = @mysql_select_db($dbname) or die ($this-> link_id = "Link DataBase Error!"
);
            
mysql_query("set names 'gbk'"
);
            return
$this -> link_id
;
        }
        function
Quit($link_id){   
//关闭连接
            
mysql_close($this->link_id
);
        }
        function
free_result($query_id){
//释放资源
            
@mysql_free_result($query_id
);
        }
        function
Query($sql_str){
//返回单条数据
            
$this->query_id = @mysql_query($sql_str
);
            
$this->num_rows = @mysql_num_rows($this->query_id
);
            
$RS=@mysql_fetch_array($this->query_id,MYSQL_ASSOC
);
            if (
$this->num_rows == 0
) {
                
$RS = FALSE
;
            }
            
$this->free_result($this->query_id
);
            return
$RS
;
        }
        function
Query_array($sql_str){
//返回多条数据 
            
$this->query_id=@mysql_query($sql_str
);
            
$this->num_rows=@mysql_num_rows($this->query_id
) ;
            if (
$this->num_rows == 0
) {
                
$RSarray = FALSE
;
                
$this->free_result($this->query_id
);
                return
$RSarray
;
            }else{
                for(
$i=0;$i<$this->num_rows;$i
++){
                    
$RSarray[$i]=mysql_fetch_array($this->query_id,MYSQL_ASSOC
);
                }
                
$this->free_result($this->query_id
);
                return
$RSarray
;
            }
        }
        function
Query_noreturn($sql_str){
//没有任何返回值
            
$this->query_id = mysql_query($sql_str
);
            
$this->affected_rows = @mysql_affected_rows
();
            if (
$this->query_id
){
                
$RS = TRUE
;
                return
$RS
;
            }else{
                
$RS = FALSE
;
                return
$RS
;
            }
        }
    }
?>

 

阅读(521) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~