Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysqli equivalent of is_resource()

Tags:

php

mysql

mysqli

I'm writing a database wrapper both in mysql and mysqli.

To get data via fetch_object() I've written a method:

public function fetch($mixed)
{
    if (is_resource($mixed))
    {
        return mysql_fetch_object($mixed);
    }
    elseif (!empty($mixed))
    {
        $result = $this->query($mixed);
        return mysql_fetch_object($result);
    }
    elseif (is_resource($this->result))
    {
        return mysql_fetch_object($this->result);
    }

    return false;
}

Now I've heard that is_resource() is not a good solution for mysqli.

How else can I check if it is a string or an mysqli_result?

like image 764
TorbenL Avatar asked Aug 30 '12 13:08

TorbenL


1 Answers

How else can I check if it is a string or an mysqli_result?

if (is_string($result)) { 
  // Result is a string
}

if ($result instanceof mysqli_result) {
  // Result is a mysqli_result object
}
like image 95
Mike B Avatar answered Oct 20 '22 00:10

Mike B