简体   繁体   English

PHP mysql PDO与'user'@'@ localhost'连接

[英]PHP mysql PDO connecting with 'user'@'@localhost'

I don't know why, but using PDO MYSQL when trying to connect with: 我不知道为什么,但是在尝试连接时使用PDO MYSQL:

$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: PDO尝试通过连接在主机之前添加一个额外的@:

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 PDOException:SQLSTATE [HY000] [1045]在第154行的C:\\ wamp \\ www \\ contratos \\ classes \\ mysql.php中,拒绝使用:'contratos'@'@ localhost'(默认密码:OUI)

I'm using a external class to handle all mysql queries, but, before it was working properly and none of my code was modified. 我正在使用一个外部类来处理所有mysql查询,但是,在它正常工作之前,我的代码都没有被修改。

Is this a PHP, MYSQL, PDO or what error/bug? 这是PHP,MYSQL,PDO还是什么错误/错误?

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 编辑:我试图连接,而不是创建用户或授予任何权限,我无法通过PHP连接,但是我可以使用MySQL Workbench连接

the char '@' in the error message is a translation error of PDO, for the fr_FR locale. 对于fr_FR语言环境,错误消息中的char'@'是PDO的转换错误。 So you need to ignore this obsolete char and investigate about your mysql user's permissions. 因此,您需要忽略此过时的char并调查有关mysql用户的权限。

这对我有用:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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