eMonk Posted November 22, 2011 Share Posted November 22, 2011 $query = "SELECT .... "; $result = $db->query($query); $num_results = $result->num_rows; if ($num_results == 0) { exit; } else { // do something $query = "SELECT .... "; $result = $db->query($query); $num_results = $result->num_rows; if ($result) { // do something } Do these both do the same? Link to comment https://forums.phpfreaks.com/topic/251640-do-these-both-to-the-same/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 22, 2011 Share Posted November 22, 2011 No. The first one tests if there were any rows returned by the query, which also indirectly detects that the query executed without any errors. The second one only tests if the query executed without any errors. There can still be zero rows in the result set at your // do something point in the code. Link to comment https://forums.phpfreaks.com/topic/251640-do-these-both-to-the-same/#findComment-1290567 Share on other sites More sharing options...
eMonk Posted November 22, 2011 Author Share Posted November 22, 2011 Thanks for the clearification. I'll go with the first one. Link to comment https://forums.phpfreaks.com/topic/251640-do-these-both-to-the-same/#findComment-1290592 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.