Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我遇到了一个问题。当我使用 PDO::prepare() 构建某个查询,然后传递参数执行时,查询将正确执行,但其中一个参数似乎没有插入到数据库中。准备语句如下所示:
... SET col = :par1-:par2 ...
所以我要做的是将值“[par1]-[par2]”放入数据库的列中。问题是第一个参数没有存储在数据库中,但破折号和第二个参数是。因此,上述查询存储在数据库中的结果值为“-[par2]”。
为什么会这样?
你在那里写的是一个整数减法。par1因此,您将减号的结果par2写入col.
par1
par2
col
相反,您应该在 PDO 之外创建字符串$par1 . '-' . $par2,然后通过其他一些命名参数将其传递:
$par1 . '-' . $par2
$stmt = $pdo->prepare('... SET col = :col'); $stmt->execute(['col' => $par1 . '-' . $par2]);