944,147 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Unsolved
  • Views: 1316
  • MySQL RSS
Nov 4th, 2009
0

What does mysql return when the selection doesnt exist?

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 5
Junior Poster
jakx12 is offline Offline
123 posts
since Jan 2009
Nov 5th, 2009
-1
Re: What does mysql return when the selection doesnt exist?
Hi, I am not sure how you are validating what mysql returns. In php, when you query the table, for example,
MySQL Syntax (Toggle Plain Text)
  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.
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: SQL statement for easier db a search
Next Thread in MySQL Forum Timeline: Remove last chars





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC