-1

所以我使用以下代码连接到我的 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() 输出错误。

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

4

1 回答 1

1

使用 mysql_errno()

在此处查看错误代码

于 2012-04-17T23:09:15.787 回答