Domanda

So I connect to my MySQL database using the following code:

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 : "";
}

The problem is, if they put in a wrong username, mysql_connect will not see anything wrong with it and try to connect to the database, which outputs an error for the mysql_select_db().

So I found this link. Now normally removing the "any" user would be doable but I'm creating a phpMyAdmin-like tool and will be connecting to different databases with all types of configurations. How can I tell which username can actually connect? And how can I differentiate between the database name not existing and the username not having access to it?

È stato utile?

Soluzione

use mysql_errno()

see error codes here

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top