【问题标题】:Dollar sign in the password causes an error密码中的美元符号导致错误
【发布时间】:2016-02-09 10:25:50
【问题描述】:

我尝试使用 PDO 连接我的数据库,以下代码运行良好:

<?php
    $koneksi = new PDO("mysql:host=localhost;dbname=tggamin1_ucp", "tggamin1_tgforum", "ppp");
    function go($location, $alert)
    {
        echo "<script>window.alert('" . $alert . "')</script>";
        echo "<meta http-equiv=\"refresh\" content=\"0;URL=".$location."\"><center>";
        return 1;
    }

当我将数据库详细信息更改为此时,它不起作用:

$koneksi = new PDO("mysql:host=localhost;dbname=tgnew_datab", "pppp", "gofahkur$lvz123");

这是我得到的错误:

致命错误:带有消息的未捕获异常“PDOException” 'SQLSTATE [HY000] [1045] 用户'tguzer'@'localhost'的访问被拒绝 (使用密码:YES)'在 /home/tggamin1/public_html/ucpp/koneksi.php:2 堆栈跟踪:#0 /home/tggamin1/public_html/ucpp/koneksi.php(2): PDO->__construct('mysql:host=loca...', 'tguzer', 'gofahkur') #1 /home/tggamin1/public_html/ucpp/profile.php(4): include('/home/tggamin1/...') #2 {main} 抛出 /home/tggamin1/public_html/ucpp/koneksi.php 在第 2 行

数据库细节没问题。

【问题讨论】:

  • Access denied for user 'tguzer'@'localhost' 仔细检查您的用户名/密码
  • Access denied for user 'tguzer'@'localhost' - 检查您对该用户帐户的访问权限。
  • 请不要发布您的密码!我编辑了您的帖子以隐藏它们,但您可以更改安装中的密码!
  • 啊,@wmk 你删除了对问题至关重要的一段代码:P
  • @hjpotter92,你能做一个回滚吗?我没有看到那个选项...

标签: php mysql pdo


【解决方案1】:

很可能是密码中的$

gofahkur$lvz123

应按字面意思理解。 PHP 尝试将其解析为变量并查找名为:

$lvz123

试试这个作为密码:

"gofahkur\$lvz123"

'gofahkur$lvz123'

PHP here 中阅读有关字符串类型的更多信息。

【讨论】:

  • 这听起来很可能。很好的收获。
  • 或者将密码用单引号而不是双引号括起来
  • @hjpotter92 我猜对了,现在它在错误日志中显示了与之前相比的完整密码,但仍然拒绝访问,还有其他可能性吗?不过帐户详细信息是正确的。
  • @SalenaFanke 尝试使用 mysql 的控制台客户端登录。 mysql -u tguzer -p tgnew_datab 看看是否可行
  • @hjpotter92 我做到了,似乎那里的访问也被拒绝了。这就是我得到的输出 Enter password: ERROR 1045 (28000): Access denied for user 'tguzer'@'localhost' (using password: YES)
猜你喜欢
  • 2018-07-13
  • 2019-05-31
  • 1970-01-01
  • 2019-10-01
  • 2017-10-05
  • 2021-11-22
  • 2020-10-20
  • 1970-01-01
相关资源
最近更新 更多