欢迎光临
我们一直在努力

新闻发布系统 (例子) 二 dbconn-PHP教程,PHP应用

建站超值云服务器,限时71元/月

<?php

class cdbabstract {
  var $_db_linkid = 0;
  var $_db_qresult = 0;
  var $rowdata = array();
  var $nextrownumber = 0;
  var $rowcount = 0;
  function cdbabstract () {
    die ("cdbabstract: do not create instances of cdbabstract! use a subclass.");
  }
  function open ($host, $user, $pass, $db = "") {
  }   
  function close () {
  }
  function selectdb ($dbname) {
  }   
  function query ($querystr) {
  }
  function seekrow ($row = 0) {
  }     
  function readrow () {
  }
  function _ident () {
    return "cdbabstract/1.1";
  }
}

class cdbmysql extends cdbabstract {
  function cdbmysql ($host, $user, $pass, $db = "") {
    $this->open ($host, $user, $pass);
    if ($db != "")  
      $this->selectdb($db);
  }   
  function open ($host, $user, $pass) {
    $this->_db_linkid = mysql_connect ($host, $user, $pass);
  }   
  function close () {
    @mysql_free_result($this->_db_qresult);
    return mysql_close ($this->_db_linkid);
  }   
  function selectdb ($dbname) {
    if (@mysql_select_db ($dbname, $this->_db_linkid) == true) {
      return 1;     
    }  
    else {
      return 0;
    }    
  }    
  function  query ($querystr) {
    $result = mysql_query ($querystr, $this->_db_linkid);
    if ($result == 0) {
      return 0;
    }  
    else {
      @mysql_free_result($this->_db_qresult);
      $this->rowdata = array();       
      $this->_db_qresult = $result;
      $this->rowcount = @mysql_num_rows ($this->_db_qresult);
      if (!$this->rowcount) {
        // the query was probably an insert/replace etc.
        $this->rowcount = 0;
      }  
      return 1;
    }
  }   
  function seekrow ($row = 0) {
    if ((!mysql_data_seek ($this->_db_qresult, $row)) or ($row > $this->rowcount-1)) {
      printf ("seekrow: cannot seek to row %d\n", $row);
      return 0;
    }
    else {
      return 1;
    }
  }     
  function readrow () {
    if($this->rowdata = mysql_fetch_array ($this->_db_qresult)) {
      $this->nextrownumber++;
      return 1;
    }
    else {
      return 0;
    }
  }   
  function _ident () {
    return "cdbmysql/1.1";
  }   
}

?> 

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 新闻发布系统 (例子) 二 dbconn-PHP教程,PHP应用
分享到: 更多 (0)