here is my connection code

// Declare Database Properties
require_once 'go-pear/PEAR/DB.php';
$user = 'user';
$pass = 'password';
$host = 'localhost';
$db_name = 'database';
// Data Source Name: This is the universal connection string
$dsn = "mysql://$user:$pass@$host/$dbname";
// DB::connect will return a PEAR DB object on success
// or an PEAR DB Error object on error
$db = DB::connect($dsn);
// With DB::isError you can differentiate between an error or
// a valid connection.
if (DB::isError($db)) {
   die ($db->getMessage());
}

Now I know it is including both db.php and PEAR.php as I threw echo statements in there and they both got printed out.
If I write a typical mysql_connect statement I can connect to the db so I know it is there.

Can anyone tell me why PEAR DB can't find it?

    $db_name = 'database';
    // Data Source Name: This is the universal connection string
    $dsn = "mysql://$user:$pass@$host/$dbname";

    You must be careful to use the same variable name. Stuff like this can bite you in the butt.

      Thanks for the spot on the Buzz however It still does not solve the problem. any other ideas.

        Updated Code

        // Declare Database Properties 
        require_once 'go-pear/PEAR/DB.php'; 
        $user = 'user'; 
        $pass = 'password'; 
        $host = 'localhost'; 
        $db_name = 'database'; 
        // Data Source Name: This is the universal connection string 
        $dsn = "mysql://$user:$pass@$host/$db_name"; 
        // DB::connect will return a PEAR DB object on success 
        // or an PEAR DB Error object on error 
        $db = DB::connect($dsn); 
        // With DB::isError you can differentiate between an error or 
        // a valid connection. 
        if (DB::isError($db)) { 
           die ($db->getMessage()); 
        }
        

        and still not found error

          Not sure... not much more I can tell you except to double check your username, password, host, and database. Are you saying that if you add:

          mysql_connect($host,$username,$pass);
          mysql_select_db($db_name);

          To your existing code, it will connect? Seems strange -- it should work. Sorry I don't have much more insight to give you, since I don't know much about your installation.

            Write a Reply...