gpt4 book ai didi

mysql - 如何修复 PDO 中对未定义函数 prepare() 的调用?

转载 作者:太空宇宙 更新时间:2023-11-03 11:09:10 26 4
gpt4 key购买 nike

问题:为什么我会收到 Call to undefined function prepare() 错误?我该如何解决?

我知道this与我的问题类似,但我不知道如何将答案应用到我的案例中。

$myNull = null;
$table="test_results";
$sql = "INSERT INTO $table (instance, uid, testid, quizstart, quizend, score)
VALUES (
:instance,
:uid,
:testid,
:quizstart,
:quizend,
:score)";

try {
/*** connect to DB ***/
$dbh = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);


$stmt = $dbh>prepare($sql); // **************ERROR HERE****************

$stmt->bindParam(':instance', $myNull, PDO::PARAM_INT);
$stmt->bindParam(':uid',$userID, PDO::PARAM_INT);
$stmt->bindParam(':testid', $tid, PDO::PARAM_STR);
$stmt->bindParam(':quizstart', $quizstart,PDO::PARAM_STR);
$stmt->bindParam(':quizend', $quizend,PDO::PARAM_STR);
$stmt->bindParam(':score', $score,PDO::PARAM_STR);
$stmt->execute();

/*** display the id of the last INSERT ***/
$lastInsertValue=$dbh->lastInsertId();

$stmt->closeCursor();

/*** close the database connection ***/
$dbh = null;
}

最佳答案

您缺少 -。试试这个

$stmt = $dbh->prepare($sql);

关于mysql - 如何修复 PDO 中对未定义函数 prepare() 的调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9816955/

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