gpt4 book ai didi

PHP 类不返回数据 PHP/MySQL

转载 作者:行者123 更新时间:2023-12-01 00:50:13 25 4
gpt4 key购买 nike

我正在尝试使用以下类从我的表中返回一条记录...

class User {
public function getCredits($uid)
{
$rs = mysql_query("select bank from `users` where id = '$uid'");
$row=@mysql_fetch_object($rs);
return $row->bank;
}
}

我使用以下内容输出此数据...

    <?php print $User->getCredits(); ?>

但是我没有得到任何东西,就好像我的代码无法读取并且我的浏览器只显示一个白页?

最佳答案

你有:

   $rs = mysql_query("select bank from `users` where id = '$uid'");

但是用 ->getCredits() 调用方法,所以 $uid 将是一个 null,你的查询最终是

 select bank from users where id = ''

假设 id 字段是标准整数/auto_increment,将有 NO 记录具有空白 id,因此您会得到一个空集。因此 fetch_object 将返回一个 bool 值 false 以指示获取失败(没有要获取的记录),并且您盲目地尝试将该 bool 值 false 用作其他地方的数据。

关于PHP 类不返回数据 PHP/MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16679249/

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