What does mysql return when the selection doesnt exist?

Reply

Join Date: Jan 2009
Posts: 103
Reputation: jakx12 is an unknown quantity at this point 
Solved Threads: 4
jakx12's Avatar
jakx12 jakx12 is offline Offline
Junior Poster

What does mysql return when the selection doesnt exist?

 
0
  #1
28 Days Ago
Ok so what does mysql return when the select query doesnt exist. So say I query the database: SELECT username FROM user WHERE username='test' AND password='test'

Ok so say test doesnt exist what will the database return because i code in java and have made a method that should return true or false. True if the the thing exists in the query and false if it doesnt. But for some reason it always returns true. It turns out because mysql returns something each time.

Thanks
There are 10 types of people in this world, those that understand binary and those that don't :).
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,749
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 331
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster
 
-1
  #2
27 Days Ago
Hi, I am not sure how you are validating what mysql returns. In php, when you query the table, for example,
  1. //query the table with username AND password
  2. $query = "select * from table where username='test' and password='test'";
  3. //execute the query AND save the resource IN $result.
  4. $result = mysql_query($query);
  5. //If the variable $result IS TRUE AND if the query RETURNS more than 0 rows, (meaning, there IS a record!) THEN display convenient message.
  6. if(mysql_num_rows($result) > 0) {
  7. echo "Username and password exists!";
  8. } ELSE {
  9. //ELSE, no records exist
  10. echo "No records found.";
  11. }
In php however, this will return false if a record doesn't exist in the table. If it has a record, then it will return all the columns of that record as a resource.
I am not sure about Java, but I think mysql will return an empty result set if no records are found.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC