gpt4 book ai didi

mysql - PDO 错误 : bound variables do not match

转载 作者:行者123 更新时间:2023-11-29 03:34:22 25 4
gpt4 key购买 nike

在第 33 行和第 54 行(我的语句执行两个查询的行)出现这些错误,但不确定原因。看起来我的绑定(bind)变量都排好了。有什么想法吗?

Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens... on line 33

Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens... on line 54

此外,我担心这是否有效,绑定(bind)是否会接受具有正确值的 $SID2 变量,但在解决上述错误之前无法判断: $SID = $dbh->lastInsertId(); $SID2 = $SID;

相关代码如下:

$dbh = new pdo('mysql:host='.$hostName.';dbname='.$dataBaseName, $user, $pass);

if(isset($_POST ['submit'])){

$user_ID = get_current_user_id();

$sql = "INSERT INTO stories(ID,
category,
genre,
rating,
story_name,
active) VALUES (
:ID,
:genre,
:rating,
:story_name,
:active)";

$stmt = $dbh->prepare($sql);
$stmt->bindParam(':ID', $user_ID, PDO::PARAM_STR);
$stmt->bindParam(':category', $_POST['category'], PDO::PARAM_STR);
$stmt->bindParam(':genre', $_POST['genre'], PDO::PARAM_STR);
$stmt->bindParam(':rating', $_POST['rating'], PDO::PARAM_STR);
$stmt->bindParam(':story_name', $_POST['story_name'], PDO::PARAM_STR);
$stmt->bindParam(':active', $a = 0, PDO::PARAM_STR);
$stmt->execute(); //line 33---error line
$SID = $dbh->lastInsertId();
$SID2 = $SID;


$sql2 = "INSERT INTO writing(ID,
SID,
text,
position,
approved) VALUES (
:ID,
:SID,
:text,
:position,
:approved)";
$stmt2 = $dbh->prepare($sql2);
$stmt->bindParam(':ID', $user_ID, PDO::PARAM_STR);
$stmt->bindParam(':SID', $SID2, PDO::PARAM_STR);
$stmt->bindParam(':text', $_POST['text'], PDO::PARAM_STR);
$stmt->bindParam(':position', $b = 0, PDO::PARAM_STR);
$stmt->bindParam(':approved', $c = 0, PDO::PARAM_STR);
$stmt->execute(); //line 54--error line

最佳答案

第一个sql中缺少一个值

VALUES (
:ID,
:category, ---> inserted
:genre,
:rating,
:story_name,
:active)";

我认为第二个应该是 stmt2 而不是 stmt(也是 bind`s)

关于mysql - PDO 错误 : bound variables do not match,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25112806/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com