gpt4 book ai didi

php - 相当于 is_resource() 的 mysqli

转载 作者:行者123 更新时间:2023-11-30 23:55:01 26 4
gpt4 key购买 nike

我正在用 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

最佳答案

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
}

关于php - 相当于 is_resource() 的 mysqli,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12197552/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com