More php and MySQL fun

Then just program in dotnet languages. There is no chance to do this so in this wise in xojo and noit even in Java.

a lot of these are “syntactic sugar” that lets you write more terse code - but not necessarily any more correct code
While the longer version is more verbose its no less correct
And someone not steeped in every last nuance of the language can read it

Both are kind of incomplete, you need a sum of both (run and check if got a result and later if rows) like:

$sql = "SELECT * FROM $table WHERE authtoken='$token' AND user='$user'";
if (($result = $db->query($sql)) && ($result->num_rows > 0)) {
  // do something with the returned rows
}

Or, in php8:

$sql = "SELECT * FROM $table WHERE authtoken='$token' AND user='$user'";
if ($db->query($sql)?->num_rows > 0) {
  // do something with the returned rows
}

(I think…)

Kinda… Nullsafe is not exactly the same thing as what you were describing in .net

Oh? Go on…

I guess it will work because in php the resulting (null > 0) in a fail probably will evaluate as false, but missed to store the rows.

But as 0 or null are treated as false, it can be even shorter:

$sql = "SELECT * FROM $table WHERE authtoken='$token' AND user='$user'";
if (($result = $db->query($sql))?->num_rows) {
  // do something with the returned rows
}