-1

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?

5
  • What is this if (!$con = @mysql_connect($h,$u,$p))? Commented Apr 17, 2012 at 23:09
  • Try removing the @s. You might be quashing a useful error. Commented Apr 17, 2012 at 23:11
  • You're not following even the link you mentioned. Commented Apr 17, 2012 at 23:14
  • And you're not returning the connection on success either, you're returning the error. Commented Apr 17, 2012 at 23:21
  • What the... there is nothing wrong with the way I'm using mysql_connect(). I don't return the connection because I call the function which makes the connection to the database. I've tried and tested this and it works. Commented Apr 17, 2012 at 23:21

1 Answer 1

1

use mysql_errno()

see error codes here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.