简体   繁体   中英

PHP mysql PDO connecting with 'user'@'@localhost'

I don't know why, but using PDO MYSQL when trying to connect with:

$host='localhost';
$db='contratos';
$user='contratos';
$password='!!contratos';
$link = new \PDO("mysql:host={$host};dbname={$db};charset=utf8", $user, $password);

PDO tries to connect adding an extra @ before host:

PDOException: SQLSTATE[HY000] [1045] Accès refusé pour l'utilisateur: 'contratos'@'@localhost' (mot de passe: OUI) in C:\\wamp\\www\\contratos\\classes\\mysql.php on line 154

I'm using a external class to handle all mysql queries, but, before it was working properly and none of my code was modified.

Is this a PHP, MYSQL, PDO or what error/bug?

edit: I'm trying to connect, not to create user or grant any rights, I can't connect through PHP, but I'm able to connect using MySQL Workbench

the char '@' in the error message is a translation error of PDO, for the fr_FR locale. So you need to ignore this obsolete char and investigate about your mysql user's permissions.

这对我有用:

$link = new \PDO("mysql:dbname=$db;host=$host", $user, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM