注册 登录
编程论坛 PHP技术论坛

php 用户包装类(更新Ing.......)

发布于 2010-05-27 10:47, 693 次点击
下面是MySQL 包装类自己写的,不是很全面,大家有什么新的方法,新的包装类都发表上来,大家一起学习下
<?php
    class mysql{
        
     private $host;
     private $name;
     private $pass;
     private $table;
     private $ut;
     
      function construct($host,$name,$pass,$table,$ut){    //连接数据库$host 数据库主机名,$name,登入账号 $pass登入密码,$table 表名,$ut 编码格式
         $this->host=$host;
         $this->name=$name;
         $this->pass=$pass;
         $this->table=$table;
         $this->ut=$ut;
         $this->connect();
     }


     function connect(){           //连接数据库
      $link=mysql_connect($this->host,$this->name,$this->pass) or die ($this->error());
      mysql_select_db($this->table,$link) or die("没该数据库:".$this->table);
      mysql_query("SET NAMES '$this->ut'");
     }

    function query($sql, $type = '') {
        if(!($query = mysql_query($sql))) $this->show('Say:', $sql);
        return $query;
    }

    function show($message = '', $sql = '') {
        if(!$sql) echo $message;
        else echo $message.'<br>'.$sql;
    }

    function affected_rows() {
        return mysql_affected_rows();
    }

    function result($query, $row) {
        return mysql_result($query, $row);
    }

    function num_rows($query) {
        return @mysql_num_rows($query);
    }

    function num_fields($query) {
        return mysql_num_fields($query);
    }

    function free_result($query) {
        return mysql_free_result($query);
    }

    function insert_id() {
        return mysql_insert_id();
    }

    function fetch_row($query) {
        return mysql_fetch_row($query);
    }
    function fetch_array($query,$result_type=MYSQL_ASSOC){
        return @mysql_fetch_array($query,$result_type);
    }

    function version() {
        return mysql_get_server_info();
    }

    function close() {
        return mysql_close();
    }



    function fn_insert($table,$name,$value){

        $this->query("insert into $table ($name) value ($value)");

    }
    function select_db($dbname){
        return mysql_select_db($dbname);
    }

   }
?>
1 回复
#2
冰镇柠檬汁儿2010-05-28 12:01
支持开源,顶一个
1