5

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.

Community
  • 1
  • 1
FurryWombat
  • 816
  • 2
  • 12
  • 28
  • can you post some code for login_class.php line: 123 (or full code if possible) – Maximus2012 Jul 19 '13 at 22:23
  • Sounds like you haven't installed PEAR properly. – Barmar Jul 19 '13 at 22:23
  • @Maximus2012 I'll bet any amount line 123 is `$this->db = DB::connect($dsn);` – Barmar Jul 19 '13 at 22:24
  • @Zachdev From http://pear.php.net/manual/en/package.database.db.db.connect.php _This function should be called statically._ – Barmar Jul 19 '13 at 22:25
  • "This package has been superseded. Please use MDB2 for new projects." http://pear.php.net/manual/en/package.database.db.php – pozs Jul 19 '13 at 22:26
  • Actually, I take that back. Line 123 is probably `die(...)`. – Barmar Jul 19 '13 at 22:26
  • @Barmar The line that results in an error is $this->db = DB::connect($dsn); – FurryWombat Jul 19 '13 at 22:27
  • This is not my code, or would be more familiar with it. Just an admin program copied over from a client's previous site. Can this be solved by uploading a new library? – FurryWombat Jul 19 '13 at 22:29
  • The `var` statements, along with constructor that has the same name as class are artifacts of PHP 4.x ... I do not know where you exhumed this code from , but please bury where you found it and salt the ground. Please, learn how to use PDO and prepared statements. – tereško Jul 19 '13 at 22:30
  • `DB->connect()` is actually not static. probably to maintain compatibility for older versions of php. http://pear.php.net/package/DB/download – pozs Jul 19 '13 at 22:32
  • @teresko, I wish that I could. Short of writing a bunch of free code for this client, which isn't going to happen, I need to find a workaround. – FurryWombat Jul 19 '13 at 22:32
  • @Maximus2012, I completely missed this, the first comment, yesterday. Posting the full code right now. – FurryWombat Jul 20 '13 at 13:41

1 Answers1

1

Sorry man,

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

for details... PDO

Zach dev
  • 1,610
  • 8
  • 15
  • 1
    So essentially, as this is not my code, and I'm not about to rewrite 6,000 lines of code for free, my only solution is to downgrade back to the deprecated PHP 5.3? – FurryWombat Jul 19 '13 at 22:30
  • 1
    The answer it's yes if you don't use some ORM or your code has handled the sql on some hardcore way. It's one o many reason why a lot people don't move from 5.3 – Zach dev Jul 19 '13 at 22:36
  • Downgrading back to 5.3 for the time being. Going to get these guys off our server ASAP. – FurryWombat Jul 19 '13 at 22:40