0

我正在尝试使用 pdo 上的准备语句插入值,但我遇到了这个错误

警告:PDOStatement::execute() [pdostatement.execute]: SQLSTATE[HY093]: Invalid parameter number: no parameters are bound in C:\wamp\www\chat\insert.php 第 23 行

$db = new PDO($dns, $user, $pass);

$sql = "INSERT INTO `conversations_t` (`fk_crname_c`, `fk_username_c`, `message_c`) VALUES (?, ?, ?)";

$sq_stat = $db->prepare($sql);
// bind column to variable for display
$sq_stat->bindColumn(1, $chatname);
$sq_stat->bindColumn(2,$username);
$sq_stat->bindColumn(3, $message);


$count=$sq_stat->execute();
4

3 回答 3

4

使用bindParam与否:bindValue_bindColumn

$sq_stat -> bindParam(1, $chatname);
$sq_stat -> bindParam(2, $username);
$sq_stat -> bindParam(3, $message);
于 2013-09-17T12:50:29.437 回答
3

bindColumn是为了结果。你想要bindValuebindParam

$sq_stat->bindValue(1, $chatname);
$sq_stat->bindValue(2,$username);
$sq_stat->bindValue(3, $message);
于 2013-09-17T12:50:59.613 回答
0

对于插入语句,请尝试将您的值作为数组传递给执行函数。

$db = new PDO($dns, $user, $pass);

$sql = "INSERT INTO `conversations_t` (`fk_crname_c`, `fk_username_c`, `message_c`) VALUES (?, ?, ?)";

$sq_stat = $db->prepare($sql);

$count = $sq_stat->execute(array($chatname, $username, $message));
于 2013-09-17T12:53:50.477 回答