0

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

2
Contributors
6
Replies
23
Views
2 Years
Discussion Span
Last Post by come_again
0

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.

0

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...

0

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

0

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();
}

Edited by gabrielcastillo

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.