<?php
try
{
$pdo = new PDO('mysql:host=localhost;dbname=clear', 'institute', 'E7@!\/');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->exec('SET NAMES "UTF8"');
ECHO 'Success!';
}
catch (PDOException $e)
{
echo 'Unable to connect to the database server.';
exit();
}
The database ‘clear’ has been setup with the user name ‘institute’ and password.
Is there any adjustment to be made to the settings? Thanks for your response.
Fatal error: Uncaught exception ‘PDOException’ with message ‘SQLSTATE[HY000] [1045] Access denied for user ‘institute’@‘localhost’ (using password: YES)’ in C:\xampp\htdocs\test_connection.php:3 Stack trace: #0 C:\xampp\htdocs\test_connection.php(3): PDO->__construct(‘mysql:host=loca…’, ‘institute’, ‘E7@!\/’) #1 {main} thrown in C:\xampp\htdocs\test_connection.php on line 3
@colshrapnel: I changed the password to ‘great’ and the connection to the database is now established. I had earlier changed, without any effect, the Server connection collation from utfmb4_unicode_ci to utf8_general_ci (though the system changed it to utf8mb4_general_ci). Thank you so much for your assistance.
I wonder whether the presence of a backslash character inside the original password would cause PHP to implement it’s escaping rules, as it would in any other string, leading to the rejection.
Within a string, certain sequences have special meaning unless the NO_BACKSLASH_ESCAPES SQL mode is enabled. Each of these sequences begins with a backslash (), known as the escape character. MySQL recognizes the escape sequences shown in Table 10.1, “Special Character Escape Sequences”. For all other escape sequences, backslash is ignored. That is, the escaped character is interpreted as if it was not escaped. For example, \x is just x.