这是我的代码:
public function getTypeByID($typeId) {
$stmt = $this->conn->prepare("SELECT type_id, description FROM type WHERE type_id = ? ");
$stmt->bind_param("i", $typeId);
if ($stmt->execute()) {
$stmt->bind_result($id_type, $description);
$stmt->fetch();
$type = array();
$type["type_id"] = $id_type;
$type["description"] = $description;
$stmt->close();
return $type;
} else {
return NULL;
}
}
我收到此错误:
致命错误:调用布尔值的成员函数execute()。
我尝试在 Mysql (PhpMyAdmin) 上执行查询,它有效。
我的类型表结构:
您的 sql 确实命名了该表,但我只是遇到了一个相同错误的实例,将我带到了此页面。
在 SQL 中调用“数据库名称”或不存在的表而不是“表名称”也会产生此错误。
可能是因为type是MySQL中的保留字。 请参阅:https://dev.mysql.com/doc/refman/5.5/en/keywords.html 尝试将表名更改为其他。
type
是MySQL的保留字。示例
SELECT 'type_id', 'description' FROM 'type' WHERE 'type_id' .........