I'm developing a PHP script with MySQL database connection. The problem I'm having is my queries have to be optimized because I handle a lot of information and, in order to do so, I'm making large queries.
To write an example I won't write a large query but one for you to be able to see what I need:
SELECT db1.name, db1.pass, db1.user_id, db2.datetime, db2.user_id
FROM database1 db1, database2 db2
WHERE db1.name = 'name'
AND db1.pass = 'pass'
AND db1.user_id = db2.user_id
What I need is to know if the query fails because the name and pass are incorrect, or because the user_id is not equal in both tables.
Basically, I need to return an Error Number or something like that in the query to be able to identify the error in the query and to output a custom message: "Your user and password are incorrect." or "You don't have permissions in database2."
Thanks in advance!