PHP一个比较简单的类

<?
/**
@class mydb
@function connect 连接数据库
**/
  class mydb
  {
    var $host;
    var $username;
    var $paswd;
    var $db;
    var $rs;
     public function mydb($host,$user,$paswd,$db)
     {
        $this->host = $host;
        $this->username = $user;
        $this->paswd = $paswd;
        $this->db = $db;
     }
    
     public function connect()
     {
        mysql_connect($this->host,$this->username,$this->paswd) or die("Connect Error!");
     }
    
     public function selectdb()
     {
        mysql_select_db($this->db) or die("Select Database Error!");
     }
    
     public function query($sql)
     {
         mysql_query("set names 'gbk'");
        $rs = mysql_query($sql) or die("Query Error!");
        $this->rs = $rs;
        return $rs;
     }
    
     public function getNextRecord()
     {
        $record = mysql_fetch_array($this->rs);
        return $record;
     }
    
     public function getRecordCount()
     {
       $num = mysql_num_rows($this->rs);
       return $num;
     }
    
     public function getAllRecords()
     {
        $records = array();
        while($record = $this->getNextRecord())
        {
           array_push($records,$record);
        }
        return $records;
     }
    
     public function close()
     {
       mysql_close();
     }
    
  }

?>


如果有什么正确的地方可以到加我Q 306631926  或是去http://www.sksto.com


评论: 1 | 引用: 0 | 查看次数: 4556
  • 1
小杰 [2008-01-07 03:38 PM]
如果功能在扩张下就很不错了~!
  • 1
发表评论
昵 称:
密 码: 游客发言不需要密码.
验证码: 验证码
内 容:
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 2000 字 | UBB代码 开启 | [img]标签 关闭