-1

I can't connect with DATABASE. Appeared error (Fatal error: in W:\domains\Rus.org\index.php on line 17)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <?php 
            $user = 'root';
            $pass = '';
            $db = 'testing';
            $host = 'localhost';

            $dsn = 'mysql:host='. $host. ';dbname='.$db;

            $pdo = new PDO($dsn, $user, $pass);
    ?>
</body>
</html>
  • What is the exact error message? – aynber Jun 15 '20 at 13:28
  • The script is failing on creating the PDO instance. Have you tried wrapping that in a try/catch to see if you can get a more helpful error message? – Quint Jun 15 '20 at 13:44

1 Answers1

-1

Try this standard code for PDO connection to get better error messages. So, you can handle them.

try {
    $pdo = new PDO($dsn, $user, $pass);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
    echo $e->getMessage();
}
Mesolaries
  • 298
  • 5
  • 14