Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Non-static method DB::connect() should not be called statically

Tags:

php

warnings

Recently upgraded our server to 5.4 and started getting the following error

Non-static method DB::connect() should not be called statically

I've researched this up & down, and every solution presented has not worked. I have tried turning off strict error reporting at the file level, directory level, and server level. The actual error that is appearing in the browser is:

DB Error: connect failed module: /path/to/login_class.php line: 49

EDIT: Posting the full code from lib_app.php:

<?php
/*--------------------------------------------------------------------------

 $RCSfile: lib_app.php,v $ 

 Purpose:   Defines App class. This class is a container for 
            application global variables such as database 
            connection.

 Copyright: 2003 ** Author Omitted **

---------------------------------------------------------------------------
    Functions:

    - none

    Classes:

        App - global application class, holds global variables  

---------------------------------------------------------------------------         
 $Log: lib_app.php,v $
 Revision 1.1.1.1  2004/08/05 23:50:39 ** Author Omitted **



--------------------------------------------------------------------------*/

if (!defined('PHP_APP')) 
    die('<br>'.__FILE__.': This program cannot function without application framework<br>');


class App{

    var $dsn;                           // db connection string
    var $db;                            // db connection object
    var $state;                         // application status
    var $debug =  CONFIG_DEBUG;         // debug status

    function App($dsn){

        $this->dsn  = $dsn;
        $this->db   = DB::connect($dsn);

        if (DB::isError($this->db)) {

            die($this->db->getMessage() . ' module: ' . __FILE__ . ' line: ' .  __LINE__ );
        }
    }   
} // class
?>

Please, has anyone solved this problem, able to assist? I've referenced many other sites including a number on Stack. Nada.

APPENDMENT: Just so we're clear, for the haters out there who would ask me to "learn PDO" or to "bury this relic and put some salt on it", while hilarious and appreciated, please note that this is NOT my code. This is in fact a relic that probably should be buried. However, it is a back-end customer management program that "came with" a client for whom we designed and coded a lot of front-end stuff, who specifically requested that the admin area not be touched. I'm not going to rewrite the whole darn thing if I'm not being paid for it, but would very much like to solve this for the greater community of people out there:

http://pear.php.net/bugs/bug.php?id=12057

http://forums.devshed.com/php-development-5/non-static-method-db-connect-should-not-be-called-statically-462291.html

http://php.brickhost.com/forums/index.php?topic=10756.0

Error message Strict standards: Non-static method should not be called statically in php

http://forums.phpfreaks.com/topic/265563-help-me-non-static-method-db/

http://forums.codewalkers.com/pear-packages-47/non-static-method-warnings-php-5t-4796.html

For the greater community of people out there who have received ZERO answers to this that would be relevant to this particular situation, and more poking and prodding about their antiquated code than anything else.

Let me lay it on you. I have already downgraded back to PHP 5.3, so the error is no longer appearing. Everything works just fine. But there needs to be some kind of answer to this problem that has been missed among all the laughing and pointing, and quick "duh... turn off error reporting" (which doesn't work), and nonspecific comments on declaring as a non-static variable (derr). No $@#! guys. If it were that simple, I wouldn't have even posted this on Stack.

For my own benefit? Not anymore. But the fact is, there will be many people looking for answers to this who will not find them elsewhere. It is my hope that somebody here can find the solution. If not, believe me, I won't be losing any sleep about it.

like image 427
FurryWombat Avatar asked Nov 12 '22 01:11

FurryWombat


1 Answers

Sorry man,

but pearl it's obsolete or his successor is MDB2 , consider upgrading to something like PDO insted

for details... PDO

like image 127
Zach dev Avatar answered Nov 14 '22 22:11

Zach dev