Connect To Database Failed

CODE:

<?php
/*
**
*/
class Dbh
{

  private $host = 'sql306.epizy.com';
  private $user = 'epiz_2524****';
  private $pass = '*******';
  private $dbname = 'epiz_2524*********';
  protected $conn;

  public function __construct() {

    $this->conn = $this->connect();

  }

  private function connect() {

    $dsn = 'mysql:host='.$this->host.';dbname='.$this->dbname;

    try {

      $conn = new PDO($dsn, $this->user, $this->pword);
      $conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
      $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

      return $conn;

    } catch (PDOException $e) {

      die("Connecting to Database Failed! \n\n" . $e->getMessage());

    }

  }

}

ERROR Message:
Connecting to Database Failed!

SQLSTATE[HY000] [1045] Access denied for user ‘epiz_2524****’@‘1**.1**.0.**’ (using password: NO)

Please help me…

Hello there,

Have you already checked this Knowledge Base article out?

1 Like

Yes still having a same problem…

ERROR Message: Connecting to Database Failed! SQLSTATE[HY000] [1045] Access denied for user ‘epiz_2524****’@‘1**.1**.0.**’ (using password: NO)

I think this is the problem:

As far as what I’m aware you require a password to connect to your database. Are you sure you did read that KB article?

1 Like

Yes… Look at my thread… My Database are there… My host, user, password and dbname are all set… i check it many times and all is good… But when connecting its not accepting…

The only possible way you would get this error is if you are not providing any password (or maybe providing a blank password). That (obviously) won’t work, and is no evidence of a server issue.

Looking at your code, I see the issue.

You define the password like this:

private $pass = '*******';

And then you use it like this:

$conn = new PDO($dsn, $this->user, $this->pword);

You’re defining it as pass but are using pword. pword is not defined, so it will be null, meaning you’re logging in without a password.

So this is clearly an issue with your code.

2 Likes

Sorry , i just change them to ****** because i dont want them to in public…

to see in public…`

How to close this thread ?? I already found the problem… i use $pword instead of $pass

… that’s what I said.

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.