Hi Guys,

I've been using pear on my local machine for the last two weeks or so without any problems - I've just tried to migrate some stuff to a remote (shared) server for the first time, and I'm having a bit of a problem.

I'm trying to connect via MDB2, using the following:

        $connection = MDB2::connect("mysql://$db_username:$db_password@$db_host/$db_database");
        if (MDB2::isError($connection)) {
        die ("Could not connect to the database: <br />".MDB2::errorMessage($connection));
    }
    ?>

which is always met with the dreaded: "Could not connect to the database: not found" error.

However:

  • I can connect using the same login details via the non-pear mysql_connect call
  • I can connect via MDB2 on my local machine using the same mdb2 code
  • I've looked via pear remote-list and MDB2 is installed on the remote machine

Any suggestions would be really, truly appreciated - I'm quite stumped. Connection code attached below. :-)

Many thanks,
- JB

    php:$db_username='tempscou_testconn';
    $db_password='conntest';
    $db_host='localhost';
    $db_database='tempscou_jts';

require_once('MDB2.php');

$connection = MDB2::connect("mysql://$db_username:$db_password@$db_host/$db_database");
    if (MDB2::isError($connection)) {
    die ("FROG1Could not connect to the database: <br />".MDB2::errorMessage($connection));
}
?>

    If you have verified that MDB2 is installed. Then the most likely problem is with the path.

    You can check that the remote server has the include path set correctly in the php.ini (if you have access to it).

    Or you can set the include path at runtime using the [man]set_include_path/man.

    Or you could set the path in the page via a variable like

    $path = "/usr/local/pear/";
    require_once($path.'MDB2.php');

      grin Hi Rincewind,

      Many thanks for the help - unfortunately no joy - I get everybody's favourite error message:

      Warning: main(MDB2.php) [function.main]: failed to open stream: No such file or directory in /home/tempscou/public_html/testdbconnection8.php on line 7
      
      Fatal error: main() [function.require]: Failed opening required 'MDB2.php' (include_path='.:/usr/local/bin/pear') in /home/tempscou/public_html/testdbconnection8.php on line 7
      

      It seems like PEAR/MDB2 isn't installed (i also tried db.php - same problem). My host assures me the path to the pear directory is correct.

      Is there any PHP procedure to test for a pear installation, and/or an mdb installation? Unfortunately I don't have shell access on the remote server. :-(

      Finally, here's the code I used to to access mdb2.php. Many thanks for the help - if you have any other suggestions, I'd love to hear them - I really am quite stumped.

      $path = "/usr/local/bin/pear/";
      require_once($path.'mdb2.php');
      
      $connection = MDB2::connect("mysql://$db_username:$db_password@$db_host/$db_database");
      	if (MDB2::isError($connection)) {
      	die ("Could not connect to the database: <br />".MDB2::errorMessage($connection));
      }

        If your host says it's installed then and the path is set in the php.ini (you can check by doing a phpinfo() test page and looking for the include path), then it should work by just doing

        require_once('mdb2.php');

        The only other thing Ican think of is a permissions problem with the path to PEAR, you would have to check with your host.

        Or you could try to set the include path at runtime (as mentioned in earlier post).

          grin Thanks for the help Rincewind - finally solved...my webhost had installed MDB2 without MDB2_driver_mysql.

          While we're on the topic, anyone have any suggestions for a solid shared-server webhost with either:

          • SSH/Telnet/The ability to install your own pear packages?
          • The vast majority of pear packages installed as standard?

          I've pretty much had to walk my web host through the PEAR thing & they still keep messing stuff up. Any suggestions most appreciated. :-)

          Cheers,
          - JB

            Write a Reply...