gpt4 book ai didi

PHP MySQLi fetch_object() 对空字符串返回 undefined variable

转载 作者:行者123 更新时间:2023-11-29 14:41:42 25 4
gpt4 key购买 nike

这个问题似乎最近才出现在我身上(我不记得以前在类似的情况下遇到过这个问题)。使用以下代码,php 循环并显示一个包含 MySQL 表中的值的表单。如果任何值包含空字符串,我会收到以下通知:

注意: undefined variable :/home/public_html/index.php 中第 XXX 行的行

只有当字符串为空时才会发生。

这是表单代码:

<?php
for ($i=1; $i<5; $i++) {
$val = $env->getVal("plan_title_$i,plan_desc_$i,plan_price_$i,plan_link_$i");
}
?>

getVal 代码提取数据的部分:

while ($tmp = $res->fetch_object()->$col) {
$row[$keys[$i]] = trim((string)$tmp);
$i++;
}

现在我考虑给该列一个空格的默认值,因为这似乎可以解决通知问题。但这是不可能的,因为它是 BLOB 字段。

如果提取的值是空字符串,有谁知道如何防止 $row 未定义?这只发生在空字符串上。

最佳答案

我们在聊天中发现这是解决方案:

while (($tmp = $res->fetch_object()->$col)!==null)

即使 db 中的值为空(空字符串),这也将允许进入循环。 while 没有输入空值,这导致 return 语句显示 undefined variable 通知。

关于PHP MySQLi fetch_object() 对空字符串返回 undefined variable ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7862639/

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