Jump to content

Code wont work on migrated server


ozzwald

Recommended Posts

Hi,

 

I have migrated a website from 5.2.6 to 5.3.13 due to the web developer going awol.

 

After many different hosts, I have found one that has PEAR, MDB2 etc that the site needs. The only problem that I can see is the newer version of PHP wont run the code.

 

I have very little experience in PHP!!!!

 

I believe this is the code bringin up the error:

 

$dsn = 'mysql://' . DATABASE_USER . ':' . DATABASE_PASS . '@' . DATABASE_HOST . '/' . DATABASE_BASE;

 

Database::get()->data =& MDB2::connect($dsn);

 

// put this code just after initializing db connection (i.e. after MDB2::connect) to hide plain text password

for ($__i = 0; $__i < count($GLOBALS['_MDB2_databases']); $__i++) {

    $GLOBALS['_MDB2_databases'][$__i]->dsn['password'] = '* hidden *';

    $GLOBALS['_MDB2_databases'][$__i]->connected_dsn['password'] = '* hidden *';

}

 

if (PEAR::isError(Database::get()->data)) {

die('Error calling script. connect.php line ~14');

}

 

 

Apart from some Deprecated warnings i get when I allow all errors, I am getting the 'Error calling script. connect.php line ~14'

 

The site is based on templates, so has many include files.

 

Many thanks in advance.

Link to comment
Share on other sites

The error is most likely stored within the Database class, and should be retrieved from it.

 

Though, I must say that using only static methods like this is usually not a good sign for your application design and/or understanding of OOP. You might want to rethink this approach, but it's unfortunately far too little code for me to say for certain. At least it's something to keep in mind.

 

PS: Please use the


tags around your code, as it helps make both your post and your code a lot easier to read.

Link to comment
Share on other sites

Hi,

 

Thanks for the pointer.

 

Here is the class.database.php file:

 


<?php

require_once 'MDB2.php';

class Database {

public $data;

    private static $instance;

    public static function get(){

        if (!isset(self::$instance)) {

            $c = __CLASS__;
            self::$instance = new $c;

        }

        return self::$instance;

    }

}

?>

 

As i said i am a complete newbie at PHP, i have always worked asp! I am learning very quickly!

Link to comment
Share on other sites

PEAR::isError() is checking if the ->data property is a PEAR_Error object. You need to trap the error in a variable so you can access it again to get the error:

 

if (PEAR::isError($error = Database::get()->data)) {
   die('Error: ' . $error->getMessage());
}

 

That should explain the problem.

 

I would recommend you make the move to exceptions sooner rather than later though, PEAR error objects are far too easy to loose. You can tell PEAR how to handle errors with the setErrorHandling() method.

Link to comment
Share on other sites

PS:

 

I dont know if this will help, make a difference:

Deprecated: Assigning the return value of new by reference is deprecated in /usr/local/lib/php/MDB2.php on line 390

Deprecated: Assigning the return value of new by reference is deprecated in /usr/local/lib/php/MDB2.php on line 1885

Deprecated: Assigning the return value of new by reference is deprecated in /usr/local/lib/php/MDB2.php on line 2572

Deprecated: Assigning the return value of new by reference is deprecated in /usr/local/lib/php/MDB2.php on line 2595

Deprecated: Assigning the return value of new by reference is deprecated in /usr/local/lib/php/MDB2.php on line 2940

 

thanks

Link to comment
Share on other sites

It won't, but you really should clean those up none the less. This is decade old code (PHP 4.x), and has been deprecated for quite a while.

 

The error message you get from PEAR tells you quite clearly what's wrong though, so you'll need to dig into the reasons why you're getting just that message from the database server.

Link to comment
Share on other sites

You're getting the deprecated notices because you're using an old PEAR package, that hasn't been updated in over two years (assuming you're even using the latest version). PHP has changed in that time, and although they aren't the cause of the issue here, you really should switch to a better, up to date database abstraction layer like PDO. Eventually those notices will turn to fatal errors.

 

Error: MDB2 Error: insufficient permissions

 

There error here is that the user you're connecting with doesn't have read access to the database specified in "DATABASE_BASE".

Link to comment
Share on other sites

Sorry for my stupidity, When you say the PEAR package is old, is that the one of my webhost, or my code?

 

I went back to check the login to the database to check, the permissions etc, to find my Database wasnt in MyPHPadmin!

 

My webhosts are looking into this. I will come back and let you know the outcome.

 

Many thanks

Link to comment
Share on other sites

Sorry for my stupidity, When you say the PEAR package is old, is that the one of my webhost, or my code?

 

PEAR's essentially just a group of PHP files (kind of a mini-framework) stored on the web server, with a command line package manager. If you're on a shared host it's possible (probably likely) that it's not been upgraded for a while, though it's also perfectly possible it's fully up to date, but the MDB2 package has just never been fixed. As I said, take a look at the PDO extension. PEAR is pretty out dated now.

 

I went back to check the login to the database to check, the permissions etc, to find my Database wasnt in MyPHPadmin!

 

If you have access to the database server, why not just create the database yourself?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.