【发布时间】:2015-04-06 18:41:02
【问题描述】:
提前感谢大家的帮助。我有一个问题让我发疯了好几个小时。我已经尝试使用几种具有完整错误检查的方法多次编写此代码。我已经尝试在字段名称上使用单引号,我已经尝试将 SQL 查询放入变量中并将其传递给 $db->prepare - 所有这些都无济于事。我检查了我的权限,一切对我来说都很好。我确定这很简单,但我睡眼惺忪,只是没有看到它。
$db = OpenDBConn();
// $query = "UPDATE agent_profiles SET ";
// $query .= "website = ?, display_email = ?, primary_phone = ?, secondary_phone = ?, secondary_phone_type = ?, ";
// $query .= "address_1 = ?, address_2 = ?, city = ?, state = ?, zip = ?, country = ?, description = ? ";
// $query .= "WHERE agent_id = ?";
$stmt = $db->prepare("UPDATE agent_profiles SET
website=?,
display_email=?,
primary_phone=?,
secondary_phone=?,
secondary_phone_type=?,
address_1=?,
address_2=?,
city=?,
state=?,
zip=?,
country=?,
description=?
WHERE agent_id=?");
$stmt->bind_param('ssssssssssssi', $this->website, $this->display_email, $this->primary_phone, $this->secondary_phone, $this->secondary_phone_type, $this->address_1, $this->address_2, $this->city, $this->state, $this->zip, $this->country, $this->description, $this->agent_id);
$stmt->execute();
$stmt->close();
$db->close();
即使有完整的错误报告和修改代码以查找 $db->error,它看起来和运行都很干净,但不会保存到表中。这里使用的函数在其他地方使用并且工作正常。有什么猜测吗?
【问题讨论】:
-
是否做过任何基本的调试,比如检查返回值?您的代码基本上假设什么都不会出错。 mysqli 在失败时返回布尔值 false。
-
为了简洁起见,我省略了任何错误检查,但请相信我,是的,我已经在流程的每个步骤中检查了错误。没有报告错误。
-
您是否禁用了自动提交?
-
bind_param 返回 true。执行返回真。没有 mysqli 错误。
-
自动提交未以编程方式禁用。但是,为了确保它不是服务器端的东西,我只是尝试使用此代码和 nada 手动提交事务。