m1k3y3
m1k3y3

Reputation: 2798

how to check if ADOdb recordset is empty

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?

Upvotes: 1

Views: 2164

Answers (2)

Daniel Faure
Daniel Faure

Reputation: 400

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
    // ...
}

Upvotes: 1

m1k3y3
m1k3y3

Reputation: 2798

before isset evaluation I converted ADODB recordset to array

$ra = $rs->getRows();

then tested if $ra array is empty

if(empty($ra)){
...
...
}

Upvotes: 1

Related Questions