hello everyone,

I am having some difficulty setting up a connection to my database. I created one on godaddy but am unable to get past this one hump:

Fatal error:  Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO)' in /home/badinvestor/public_html/config/connection.php:9
Stack trace:
#0 /home/badinvestor/public_html/config/connection.php(9): PDO->__construct('mysql:host=loca...', 'root', '')
#1 /home/badinvestor/public_html/classes/registration.php(45): connect_db()
#2 /home/badinvestor/public_html/views/register.php(20): registration->get_schools()
#3 /home/badinvestor/public_html/register.php(10): require_once('/home/badinvest...')
#4 {main}
  thrown in /home/badinvestor/public_html/config/connection.php on line 9

My line 9 connection is as follows:

// database info

define('HOST','localhost');
define('DB','qbank');
define('USER','registration');
define('PASS','register');

function connect_db()
{
    $db = new PDO('mysql:host='.HOST.';dbname='.DB,USER,PASS);
    return $db;
}

Please note that I already used 'root' and '' as username and password respectively with no luck so I created this as a test user... Looking up online for people with similar problems didn't really turn out to be helpful.

Any thoughts?

Thank you,

come_again

Recommended Answers

All 6 Replies

Try this to see if you get the error

$dbh = new PDO('mysql:host=localhost;dbname=qbank', 'registration', 'register');

if you get error, post error.. Godaddy used to have url's for the host string.. not sure if they are doing that anymore.. which means you would have to put : database.host.securedserver.com Something like this instead of localhost.. you can always try putting 127.0.0.1 as well.

hmm i read that godaddy has changed it to localhost. the url would like like what? qbank.host.mywebsite.com?

i'm getting the same error message...

Did you try the other 2 sugestions?

yes i tried them. but to confirm what would the URL look like exactly?

run this to see if pdo is available:

try {
    $conn = new PDO('mysql:host=localhost;dbname=myDatabase', $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
    echo 'ERROR: ' . $e->getMessage();
}

hey, so i just ended up reseting my entire cpanel... and it worked. no idea why.
thanks for your help gabrielcastillo.
cheers,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.