6

私はmysqlmysqliの両方でデータベースラッパーを書いています。

経由fetch_object()でデータを取得するには、メソッドを作成しました。

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;
}

今、私はそれis_resource()がmysqliにとって良い解決策ではないと聞きました。

それが文字列なのかmysqli_resultなのかを他にどのように確認できますか?

4

1 に答える 1

24

それが文字列なのか mysqli_result なのか、他にどのように確認できますか?

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

if ($result instanceof mysqli_result) {
  // Result is a mysqli_result object
}
于 2012-08-30T13:13:34.387 に答える