Jump to content

Do these both to the same?


eMonk

Recommended Posts

$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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.