【问题标题】:mysql_connect - Access Denied to DB or DB doesn't exist?mysql_connect - 拒绝访问数据库或数据库不存在?
【发布时间】:2012-04-17 23:05:42
【问题描述】:

所以我使用以下代码连接到我的 MySQL 数据库:

function dbConnect($h,$u,$p,$n) {
  if (!$con = @mysql_connect($h,$u,$p)) {$err = err("There is a problem connecting to the database. ".mysql_error());}
  else if (!@mysql_select_db($n,$con)) {$err = err("The database \"{$n}\" could not be found. Check your spelling, make sure the database exists, and that your database credentials allows you access to this database.");}
  return (isset($err)) ? $err : "";
}

问题是,如果他们输入了错误的用户名,mysql_connect 将不会发现任何问题并尝试连接到数据库,这会为 mysql_select_db() 输出错误。

所以我找到了this link。现在通常删除“任何”用户是可行的,但我正在创建一个类似 phpMyAdmin 的工具,并将连接到具有所有类型配置的不同数据库。我怎么知道哪个用户名可以实际连接?以及如何区分不存在的数据库名称和无法访问它的用户名?

【问题讨论】:

  • 这是什么if (!$con = @mysql_connect($h,$u,$p))
  • 尝试删除@s。您可能正在取消一个有用的错误。
  • 你甚至没有关注你提到的link
  • 而且您也没有成功返回连接,而是返回了错误。
  • 什么...我使用 mysql_connect() 的方式没有任何问题。我没有返回连接,因为我调用了与数据库建立连接的函数。我已经对此进行了尝试和测试,它确实有效。

标签: php mysql mysql-connect


【解决方案1】:

使用 mysql_errno()

查看错误代码here

【讨论】:

    猜你喜欢
    • 2012-06-07
    • 1970-01-01
    • 1970-01-01
    • 2020-12-07
    • 2016-03-02
    • 2014-04-17
    • 1970-01-01
    • 2011-01-20
    • 2014-06-14
    相关资源
    最近更新 更多