Location: PHPKode > scripts > PHP Desk Library > php-desk-library/dbquery.php
<?
  if (!$_PHPDESK["mysql"]) {
    die("dbquery loaded without mysql information set");
  }

  
  $mysql_cid = mysql_connect($mysql["hostname"], $mysql["username"], $mysql["password"]);
  mysql_select_db($mysql["database"]);

  class dbquery {
    var $resource;
    var $querytext;
    var $cid;
    var $numrows;
    var $affrows;
    var $row;
    var $error;

    function dbquery($query = "", $autonextrow=0) {
      $this->cid = $GLOBALS["mysql_cid"];
      if ($query) {
        $this->query($query);
        if ($autonextrow) { $this->nextrow(); }
      }
    }
    
    function database($db) {
      if (mysql_select_db($db)) { return 1; } else { return 0; }
    }
    
    function query($query) {
      $this->querytext = $query;
      if ($this->resource = @mysql_query($query)) {
        $this->numrows = @mysql_num_rows($this->resource);
        $this->affrows = @mysql_affected_rows($this->cid);
        return 1;
      } else {
        $this->error = mysql_error();
        unset($this->resource);
        unset($this->numrows);
        unset($this->affrows);
        unset($this->row);
        return 0;
      }
    }
    function nextrow() {
      if ($this->row = mysql_fetch_object($this->resource)) { return 1; } else { return 0; }
    }
  }
?>
Return current item: PHP Desk Library