Call to a member function bind_param() on boolean(在布尔值上调用成员函数 bind_param())
问题描述
我尝试在php中将参数绑定到sql(mysqli),但是出现上面写的错误代码.这是我写的代码:
I try to bind parameters to sql (mysqli) in php, but there is an error code as written above. This is the code I wrote:
$stmt = $conn->prepare("INSERT INTO assignments (Classes_has_Subjects_classesHasSubjectsId, assignmentName, gradeForAssignment,protectiveGrade)
VALUES (?, ?, ?, ?)");
if ($stmt = false)
{
echo "false";
}
else{
$stmt->bind_param("sss", $classesHasSubjectsId, $assignmentName, $gradeForAssignment, $protectiveGrade);
$stmt->execute();
}
这里是错误信息:11
致命错误:在布尔值上调用成员函数 bind_param()
Fatal error: Call to a member function bind_param() on boolean in
怎么了?
推荐答案
<?php
$stmt = $conn->prepare("INSERT INTO assignments (Classes_has_Subjects_classesHasSubjectsId, assignmentName, gradeForAssignment,protectiveGrade)
VALUES (?, ?, ?, ?)");
if (!$stmt) {
echo "false";
}
else {
$stmt->bind_param("ssss", $classesHasSubjectsId, $assignmentName, $gradeForAssignment, $protectiveGrade);
$stmt->execute();
}
if ($stmt = false) 表示您将 false 分配给 $stmt.将其替换为 if (!$stmt).
if ($stmt = false) means you're assigning false to $stmt. Replace it with if (!$stmt).
您绑定了 4 个参数,但只提供了 3 种类型的值.我在 bind_param 函数中添加了一个 s,假设您的所有值都是字符串.如果某些值是整数,则用 i 替换相应的 s.如果有双打,替换为 d.
You're binding 4 parameters but only providing 3 types of values. I added a s in the bind_param function, assuming all your values are string. If some of the values are integers replace the corresponding s with an i. If there are doubles, replace with a d.
您确定 assignments 表中第一个字段的名称是 Classes_has_Subjects_classesHasSubjectsId?
Are you sure the first field's name in the assignments table is Classes_has_Subjects_classesHasSubjectsId?
这篇关于在布尔值上调用成员函数 bind_param()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在布尔值上调用成员函数 bind_param()
基础教程推荐
- PHP 类:全局变量作为类中的属性 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 如何替换eregi() 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
