db connection problem

Discussion in 'PHP' started by promotingspace.net, Sep 15, 2008.

  1. #1
    i have a login script and have used it several times. but i'm unable to connect in 1 host
    it is known to use PEAR in the code and the config file is:
    
    
    <?php
    
    function handlePearError($error) {
    	header('HTTP/1.0 500 Internal Server Error');
    	//die("$error->message<br />$error->userinfo"); // uncomment this to debug
    	die('Error ocurred, please try again later');
    }
    
    
    function &db_connect() {
    	require_once 'DB.php';
    	$dsn = "mysql://user:pass@unix+localhost/db_name";
    
    	$db = DB::connect($dsn);
    
    	if (DB::isError($db)) {
    		die("Database connection failed.");
    	}
    
    	$db->setFetchMode(DB_FETCHMODE_OBJECT);
    	$db->setErrorHandling(PEAR_ERROR_CALLBACK, 'handlePearError');
    	
    	return $db;
    }
    ?>
    
    PHP:
    currently i get this error:
    Database connection failed.
    why do you think i can't connect to database?
    how can i see the error?
     
    promotingspace.net, Sep 15, 2008 IP
  2. gameOn

    gameOn Member

    Messages:
    624
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    35
    #2
    open DB.php , and check if the database details are entered correct..
     
    gameOn, Sep 15, 2008 IP
  3. promotingspace.net

    promotingspace.net Peon

    Messages:
    361
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    database details are in config.php:
    you saw the line:
    $dsn = "mysql://user:pass@unix+localhost/db_name";
    and they are correct
     
    promotingspace.net, Sep 15, 2008 IP
  4. promotingspace.net

    promotingspace.net Peon

    Messages:
    361
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    oh i hadn't added the user to database
     
    promotingspace.net, Sep 15, 2008 IP