【发布时间】:2011-08-13 12:30:09
【问题描述】:
我通过 URL 将值传递到 PHP 页面并在 MySQLi 查询中使用它们。问题是对于整数列,空字符串被转换为零,而实际上它需要为 NULL。
如何使用 PHP/MySQLi 从 URL 中传递的参数将 NULL 放入整数列?
更新: 这是我如何使用传入参数和准备好的语句进行插入的示例。我需要在 DB 上为 NULL 的是 $specialtyType。
function InsertItem($itemID, $ownerID, $specialtyType)
{
$this->insertItemStmt->bind_param("ssi", $itemID, $ownerID, $specialtyType);
$this->insertItemStmt->execute();
如果我在 bind_param 之前添加 Jason 建议的行(设置一个中间变量并在 bind_param 中使用它而不是 $specialty_type),它会在 execute() 之后包含 0。
【问题讨论】:
-
你试过
$specialtyType = null吗? -
我最终重写了它,以便如果参数应该为空,则根本不会将参数传递给服务器,但我怀疑将其设置为 NULL(不带引号)确实会起作用。跨度>
标签: php mysql mysqli null integer