警告:mysqli_free_result()期望参数1为mysqli_result,给定布尔值 [英] Warning: mysqli_free_result() expects parameter 1 to be mysqli_result, boolean given

查看:262
本文介绍了警告:mysqli_free_result()期望参数1为mysqli_result,给定布尔值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为什么收到此错误消息:

Why am I getting this error message:

警告:mysqli_free_result()期望参数1为mysqli_result,给定布尔值

Warning: mysqli_free_result() expects parameter 1 to be mysqli_result, boolean given

我的代码是:

$statement = "INSERT INTO table1 (data1, data2) VALUES ('$variable1', '$variable2')";

if ($result = mysqli_query($conn,$statement)) {
echo "New record added successfully";
          } else {
    echo "Error adding records: " . $result . "<br>" . mysqli_error($conn);
}

echo "Adding records finished. ";

mysqli_free_result($result);

推荐答案

中所述mysqli_query手册:

失败时返回FALSE.对于成功的SELECT,SHOW,DESCRIBE或EXPLAIN查询,mysqli_query()将返回mysqli_result对象.对于其他成功的查询,mysqli_query()将返回TRUE.

Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object. For other successful queries mysqli_query() will return TRUE.

您的插入查询将返回true或false,但不会返回对象.因此,调用mysqli_free_result在这里不起作用.

Your insert query will return true or false, but not an object. So, calling mysqli_free_result will not work here.

这篇关于警告:mysqli_free_result()期望参数1为mysqli_result,给定布尔值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆