我正在mysql和mysqli中编写数据库包装器。
为了通过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?
否则我如何检查它是字符串还是mysqli_result?
if (is_string($result)) {
// Result is a string
}
if ($result instanceof mysqli_result) {
// Result is a mysqli_result object
}