gpt4 book ai didi

php - 当某些数据丢失时,mysql $result 是否设置?

转载 作者:行者123 更新时间:2023-11-29 14:37:21 24 4
gpt4 key购买 nike

如果没有要插入的数据,mysql会发生什么情况。意思是下面的代码:

            $result = mysql_query("INSERT INTO table (column1, column2) 
VALUES ('$var1', '$var2')");
mysql_close();

如果 $var2 为空,后续的 if($result) 会发生什么情况?$var1 和 $var2 是从数组中提取的,如下所示:

        $var1= $data->var1;
$var2= $data->var2;

我碰巧知道 var2 没有(或者不应该返回任何内容,因为它不在数组检索的原始数据集中)。

基本上我的页面停止了,当它应该进入这个if时什么也没有发生...但事实并非如此。这有任何意义吗?我认为只要 $result 内部至少发生了一些事情,它就存在?问题是,else 也没有发生,整个代码只是停在中间......:(

最佳答案

       $result = mysql_query("INSERT INTO table (column1, column2) 
VALUES ('$var1', '$var2')");
mysql_close();

If $var2 is empty, what happens to the subsequent if($result)?

没有数据“丢失”。空字符串 ("") 是完全有效的字段值。

<小时/>

$var1 and $var2 were extracted from an array like so:

    $var1= $data->var1;
$var2= $data->var2;

您无法从这样的数组中获取数据,所以,不,它们不是。

<小时/>

The thing is, the else isn't happening either, the whole code just stops in the middle... :(

打开错误日志记录。您在某处没有看到错误。

关于php - 当某些数据丢失时,mysql $result 是否设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8771943/

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