In the preceding note,
$sth = ibase_query($dbh, $stmt);
^^^^ this is a query (or statement handle)
while ($row = ibase_fetch_object($sth)) {
^^^^ this is a result
So the end is wrong, because $sth isn't a result
ibase_free_result($sth); // <-------
ibase_close($dbh);
It should really read as follows:
ibase_free_result($row);
ibase_free_query($sth);
ibase_close($dbh);