Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Non-static method DB::DB() cannot be called statically error

Status
Not open for further replies.

tewari68

Programmer
Jan 25, 2005
87
US
Hi,
I upgraded from apache1.x and php4.x to apache2 and php5.0.5 (debian).
Now my code breaks, though no changes have been made in the code, giving me the following error error mesg
Code:
Non-static method DB::DB() cannot be called statically
.

Appreciate any help in this regards.
Thank You
 
Ok DB.php is a class, here is the code
Code:
<?php

class DB
{
    var $host = '';
    var $user = '';
    var $password = '';
    var $database = '';
    var $persistent = false;

    var $conn = NULL;

    var $result = false;

    function DB($host, $user, $password, $database, $persistent = false)
    {
        $this->host = $host;
        $this->user = $user;
        $this->password = $password;
        $this->database = $database;
        $this->persistent = $persistent;

        return $this;
    }

    function open()
    {
        if ($this->persistent) {
            $func = 'mysql_pconnect';
        } else {
            $func = 'mysql_connect';
        }

        //print "host=" . $this->host . "<br>";
        //print "user=" . $this->user . "<br>";
        //print "password=" . $this->password . "<br>";

        $this->conn = $func($this->host, $this->user, $this->password);
        if (!$this->conn) {
            return false;
        }

        if (!@mysql_select_db($this->database, $this->conn)) {
            return false;
        }

        return true;
    }

    function close()
    {
        return (@mysql_close($this->conn));
    }

    function error()
    {
        return (mysql_error());
    }

    function query($sql = '')
    {
        $this->result = @mysql_query($sql, $this->conn);

        return ($this->result != false);
    }

    function listFields($sql = '')
    {
        $this->result = @mysql_list_fields($this->database, $sql, $this->conn);

        return ($this->result != false);
    }

    function affectedRows()
    {
        return (@mysql_affected_rows($this->conn));
    }

    function numRows()
    {
        return (@mysql_num_rows($this->result));
    }

    function numFields()
    {
        return (@mysql_num_fields($this->result));
    }

    function freeResult()
    {
        return (@mysql_free_result($this->result));
    }

    function fetchObject()
    {
        return (@mysql_fetch_object($this->result, MYSQL_ASSOC));
    }

    function fetchArray()
    {
        return (@mysql_fetch_array($this->result, MYSQL_NUM));
    }

    function fetchAssoc()
    {
        return (@mysql_fetch_assoc($this->result));
    }

    function dataSeek($page)
    {
        return (@mysql_data_seek($this->result, $page));
    }

    function getResult($num)
    {
        return (@mysql_result($this->result, $num));
    }


    function fieldName($num)
    {
        return (@mysql_field_name($this->result, $num));
    }

}
this class is being called as follows on the login page
Code:
<?
require_once($PUREMAILWEBCLASSES . "DB.php");
global $HOST, $USER, $PASSWORD, $DB_MAIN, $GreatDomain, $CltsFolder, $USERDATAMAILFILEDIR, $BASEPATHSECURE, $GreatDomain,$options;
DB::DB($HOST, $USER, $PASSWORD, $DB_MAIN);//=>call to DB class
Thanks

 
The PHP Online manual section on the "static" keyword in PHP 5.x objects says that "Declaring class members or methods as static makes them accessible without needing an instantiation of the class. A member declared as static can not be accessed with an instantiated class object (though a static method can)."

It sounds to me like you need to either start declaring the class' methods and members static or instantiate the class and reference the methods via the object.



Want the best answers? Ask the best questions! TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top