Migration of website... PHP/Mysql -which path for DB.php

Hi,

I have two websites:

website1.com and website2.com

I didn't write either but have successfully moved all the files from website1.com to website2.com

I (thought) I installed all the correct php modules and website2 is mostly up and running. However, my boss found that when we go to a particular page;

Okay, so I found where the original DB.php lives and (since I moved ALL the files over) -I made reference to that file. Bad things happened or more explicitly
"DB Error: not found"
Which is strange because the exact same code runs well on website1.com

Anyways, I believe this is a case where the Pear Libraries are in a different location than where the code assumed it to be. One huge hint is that my init.php file has the following string;

<?php ini_set("include_path", ".:./include:/usr/lib/php"); ?>
<?php
  require_once 'DB/DataObject.php';
  
  $config = parse_ini_file('db/dataobjects.ini',TRUE);
  foreach($config as $class=>$values) {
    $options = &PEAR::getStaticProperty($class,'options');
    $options = $values;
  }
?>

and a general "Find" linux command gives me thus;

-bash-3.2$ find /home/mywebsiteDirectory -name 'DB.php'
/home/mywebsiteDirectory/php/DB.php
/home/mywebsiteDirectory/php/DB/NestedSet/DB.php
/home/mywebsiteDirectory/public_html/dev2/nps/include/DB/DB.php
/home/mywebsiteDirectory/public_html/prod_backup/nps/include/DB/DB.php
/home/mywebsiteDirectory/public_html/include/DB/DB.php
/home/mywebsiteDirectory/public_html/backup/include/DB/DB.php
/home/mywebsiteDirectory/public_html/dev/nps/include/DB/DB.php
/home/mywebsiteDirectory/public_html/dev_experimental/nps5/nps2/include/DB/DB.php
/home/mywebsiteDirectory/public_html/dev_experimental/nps/trunk/include/DB/DB.php
/home/mywebsiteDirectory/public_html/dev_experimental/nps6/include/DB/DB.php
/home/mywebsiteDirectory/public_html/dev_experimental/gcc/emprise/include/DB/DB.php
/home/mywebsiteDirectory/public_html/dev_experimental/nps3/nps/include/DB/DB.php
-bash-3.2$

is there any other string I should add to my include?
do you need any other information to help/

thanks

---------- Post updated at 08:16 PM ---------- Previous update was at 06:34 PM ----------

I'm still stuck on this. Here is the original code which runs fine on website1

require_once 'DB.php';

$db_engine = 'mysql';
$db_user = 'mywebsiteDirectory';
$db_pass = '*********';
$db_host = 'localhost';
$db_name = 'mywebsiteDirectory_testlogin';

$datasource = $db_engine.'://'.
              $db_user.':'.
              $db_pass.'@'.
               $db_host.'/'.
                $db_name;


$db_object = DB::connect($datasource, TRUE);
echo $datasource;
/* assign database object in $db_object, 

if the connection fails $db_object will contain

the error message. */

// If $db_object contains an error:

// error and exit.

if(DB::isError($db_object)) {
    die($db_object->getMessage());
}

$db_object->setFetchMode(DB_FETCHMODE_ASSOC);

// we write this later on, ignore for now.

include('check_login2.php');

?>

Your error message says:

Please cut and past the contents of this file in your next post, so we can see exactly what is going on in this file.

/home/mywebsiteDirectory/public_html/include/test_place/db_connect.php

1 Like

There is an old saying that 90% of all Unix problems are permission problems. Did you check the file systems permissions and ownerships of the file(s) and made sure they match?

Just a suggestion.

I hope this helps.

bakunin

1 Like

No problem;

require_once 'DB.php';

$db_engine = 'mysql';
$db_user = 'mywebsiteDirectory';
$db_pass = '*********';
$db_host = 'localhost';
$db_name = 'mywebsiteDirectory_testlogin';

$datasource = $db_engine.'://'.
              $db_user.':'.
              $db_pass.'@'.
               $db_host.'/'.
                $db_name;


$db_object = DB::connect($datasource, TRUE);
echo $datasource;
/* assign database object in $db_object, 

if the connection fails $db_object will contain

the error message. */

// If $db_object contains an error:

// error and exit.

if(DB::isError($db_object)) {
    die($db_object->getMessage());
}

$db_object->setFetchMode(DB_FETCHMODE_ASSOC);

// we write this later on, ignore for now.

include('check_login2.php');

?>

There is no line numbers in the file above.

Would be good if you could post your code in a way which others can read the line numbers.

Line 7 is;

require_once 'DB.php';

---------- Post updated at 09:58 AM ---------- Previous update was at 09:54 AM ----------

1        <?php
2        
3        
4        //require the PEAR::DB classes.
5        
6        
7        require_once 'DB.php';
8        
9        
10        $db_engine = 'mysql';
11        $db_user = 'mywebsiteDirectory'; //use this as a username as well as a websitename
12        
13        $db_pass = '********';
14        $db_host = 'localhost';
15        $db_name = 'mywebsiteDirectory_testlogin';
16        
17        $datasource = $db_engine.'://'.
18          $db_user.':'.
19          $db_pass.'@'.
20          $db_host.'/'.
21          $db_name;
22        
23        
24        $db_object = DB::connect($datasource, TRUE);
25        
26        /* assign database object in $db_object, 
27        
28        if the connection fails $db_object will contain
29        
30        the error message. */
31        
32        // If $db_object contains an error:
33        
34        // error and exit.
35        
36        if(DB::isError($db_object)) {
37        die($db_object->getMessage());
38        ?>

OK, Thanks!

I suggest you replace 'DB.php' with the full path.

What is the full path, BTW?

And what are the permissions for that file (output of ls -la)... ?

I've tried that with the full path (that I think it is), I listed a search for the full path and tried replacing it with several.

When I replace it with

require_once '/home/mywebsiteDirectory/public_html/include/DB/DB.php'

-for example... I get the not useful Pear error message

"DB Error: not found"

I've found this useful tutorial on the Pear DB library here

--- As an interesting sidenote -the ex-contractor who wrote this (who has since gone on to bigger and better things) used this method of connecting to our MySQL database only once. Elsewhere in the code (on completely separate pages) -he uses a different method. Perhaps he abandoned this method?

---------- Post updated at 10:18 AM ---------- Previous update was at 10:13 AM ----------

and

Genius!!!

Of course the permissions weren't transferred when I moved the files between websites.

-bash-3.2$ ls -al ~/public_html/include/DB/DB.php
-rw-r--r-- 1 mywebsiteDirectory mywebsiteDirectory 38997 Apr 16 10:44 /home/mywebsiteDirectory/public_html/include/DB/DB.php

That's why when you entered the full path it did not work.

First you must confirm you are actually using the file and then confirm what the access rights/permissions are.

It's really quite easy when you get the hang of it.

Unfortunately it is still no dice.

I 'chmoded' the file in question so that it executes.

The error is the same.

"DB Error: not found"

Well, if you don't post the output of ls -la of the file that shows the permissions, we can't easily help you.

AH.. I see it it now... sorry.....

It's readable.... so something else is missing somewhere.

I did it is above.
-bash-3.2$ ls -al ~/public_html/include/DB/DB.php -rw-r--r-- 1 mywebsiteDirectory mywebsiteDirectory 38997 Apr 16 10:44 /home/mywebsiteDirectory/public_html/include/DB/DB.php
But I accidentally solved this error.

Our customer service agent noticed that a tool that we use (where the page is hosted by our current website: website2) was pointing to the database on our old website; website1.

I looked at the code and found out that indeed the old IP address was hard coded in there.

When I changed that IP address to the new IP address -suddenly things work.

Very strange. Thanks to all.

That issue would not cause an error on line 7.. so you missed something along the way.

After pointing to a direct location of DB.php -the error was:

"DB Error: not found"

Now (miraculously) the error is gone.

Then again it could be that I asked the hosting company to reinstall the DB pear module which they did "globally"

Perhaps that is what fixed it.

Thanks!

so it was both that DB.php was not in the include_path AND that the ip address of the db hostname had not veen updated. Is that a correct assessment?