免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1365 | 回复: 0

mysql简单类 [复制链接]

论坛徽章:
0
发表于 2007-10-15 15:45 |显示全部楼层

                                刚刚学习类,写了一个简单的mysql类。试着调用这个类后,终于对类和oop有些新的认识。
db_mysql.php
Host = $HOST;
                $this->User = $USER;
                $this->Password = $PASS;
                $this->Database = $DATABASE;
        }
        function link_id() {
                return $this->Link_ID;
        }
        function query_id() {
                return $this->Query_ID;
        }
        function connect() {
                $this->Link_ID = mysql_connect($this->Host,$this->User,$this->Password);
                return $this->Link_ID;
        }
        function select_db() {
                if ($this->Link_ID) {
                        mysql_select_db($this->Database);
                }
        }
        function query($sql) {
                $this->sql = $sql;
                $this->Result = mysql_query($this->sql,$this->Link_ID);
                return $this->Result;
        }
        function insert($sql) {
                $this->sql = $sql;
                $this->Result = mysql_query($this->sql,$this->Link_ID);
                return $this->Result;
        }
        function update($sql) {
                $this->sql = $sql;
                $this->Result = mysql_query($this->sql,$this->Link_ID);
                return $this->Result;
        }
        function delete($sql) {
                $this->sql = $sql;
                $this->Result = mysql_query($this->sql,$this->Link_ID);
                return $this->Result;
        }
        function free() {
                if ($this->Query_ID) {
                        @mysql_free_result($this->Query_ID);
                        $this->Query_ID = 0;
                }
        }
        function Close(){
                if ($this->Link_ID) {
                        mysql_close($this->Link_ID);
                }
                else {
                        @mysql_close($this->Link_ID);
                }
        }
}
?>
调用类的例子:
connect();        //调用方法
if ($mysql->Link_ID) {
  echo "success";
}else{
  echo "fail";
}
?>
               
               
               
               
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/8552/showart_400975.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP