【发布时间】:2016-04-14 16:03:35
【问题描述】:
这是发帖形式:
$funcname->name= htmlentities($_POST['name']);
$funcname->insert();
这将是类 funcname 上的函数 insert,它将数据插入到名为 name
的列中$this->conn->beginTransaction();
$stmt = $this->conn->prepare("INSERT INTO nameTBL (name) values (:name)";
$stmt->bindParam(':name', $this->name, PDO::PARAM_INT);
if ($stmt->execute()) {
$this->conn->commit(); //This will save your changes
$this->conn->exec('UNLOCK TABLES ' . self::$table_name);
header('Location: ../');
exit();
} else {
$this->conn->rollBack(); //This will undo your changes
$this->conn->exec('UNLOCK TABLES ' . self::$table_name);
header('Location: ../');
exit();
}
现在的问题是我设置了 PDO::PARAM_INT,它不应该允许字符但只允许整数,为什么我能够将文本发布到数据库(表)?
我有什么方法可以在这里高度限制 bindParam 上的数据类型。
提前致谢。
【问题讨论】: