ozzwald Posted September 20, 2012 Share Posted September 20, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/268596-code-wont-work-on-migrated-server/ Share on other sites More sharing options...
Christian F. Posted September 20, 2012 Share Posted September 20, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/268596-code-wont-work-on-migrated-server/#findComment-1379539 Share on other sites More sharing options...
ozzwald Posted September 20, 2012 Author Share Posted September 20, 2012 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! Quote Link to comment https://forums.phpfreaks.com/topic/268596-code-wont-work-on-migrated-server/#findComment-1379540 Share on other sites More sharing options...
Adam Posted September 20, 2012 Share Posted September 20, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/268596-code-wont-work-on-migrated-server/#findComment-1379548 Share on other sites More sharing options...
ozzwald Posted September 20, 2012 Author Share Posted September 20, 2012 Hi, I am now getting this error: Error: MDB2 Error: insufficient permissions I will read up on what you said Adam. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/268596-code-wont-work-on-migrated-server/#findComment-1379551 Share on other sites More sharing options...
ozzwald Posted September 20, 2012 Author Share Posted September 20, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/268596-code-wont-work-on-migrated-server/#findComment-1379552 Share on other sites More sharing options...
Christian F. Posted September 20, 2012 Share Posted September 20, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/268596-code-wont-work-on-migrated-server/#findComment-1379556 Share on other sites More sharing options...
Adam Posted September 20, 2012 Share Posted September 20, 2012 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". Quote Link to comment https://forums.phpfreaks.com/topic/268596-code-wont-work-on-migrated-server/#findComment-1379557 Share on other sites More sharing options...
ozzwald Posted September 20, 2012 Author Share Posted September 20, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/268596-code-wont-work-on-migrated-server/#findComment-1379560 Share on other sites More sharing options...
Adam Posted September 20, 2012 Share Posted September 20, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/268596-code-wont-work-on-migrated-server/#findComment-1379563 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.