1

I ran into the problem while checking emptiness of the ADODB5 recordset

$db = ADONewConnection($dbdriver);
$db->Connect($dbhost, $dbuser, $dbpass, $dbname);
$rs = $db->Execute($query);

now, if I try to check recordset

if(isset($rs[0]))
...
...

I get the error Cannot use object of type ADORecordSet_mysqli as array

How do you check whether returned recordset is or isn't empty?

m1k3y3
  • 2,762
  • 8
  • 39
  • 68

2 Answers2

1

before isset evaluation I converted ADODB recordset to array

$ra = $rs->getRows();

then tested if $ra array is empty

if(empty($ra)){
...
...
}
m1k3y3
  • 2,762
  • 8
  • 39
  • 68
1

If the $db->Execute($query) method fails, it may not return a ADORecordSet object. I would not call the $rs->getRows() method before being sure $rs is valid, so,

if (is_subclass_of($rs, 'ADORecordSet') AND $rs->recordCount()) {
    // I have rows
    // ...
}
Daniel Faure
  • 391
  • 6
  • 14