gpt4 book ai didi

php mysql bind param 参数

转载 作者:行者123 更新时间:2023-11-30 23:58:05 28 4
gpt4 key购买 nike

我第一次尝试使用准备好的语句并使用以下代码遇到以下问题

错误:

Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given

代码:

$stmt = mysqli_prepare($db, "INSERT INTO fragrances(name, description, essentialoils, topnotes, middlenotes, basenotes, reference, year, type, price, fragrancehouse, triangle, extractname, extractreference, extractprice, extractfragrancehouse, disccolour, collarcolour, actuatorcolour)
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
mysqli_stmt_bind_param($stmt, 'sssssssssssssssssss', $name, $description, $essentialoils, $topnotes, $middlenotes, $basenotes, $reference, $year, $type, $price, $fragrancehouse, $triangle, $extractname, $extractreference, $extractprice, $extractfragrancehouse, $disccolour, $collarcolour, $actuatorcolour);

mysqli_stmt_execute($stmt);

我在这里查看了许多不同的问题,但他们的解决方案似乎都不适用于我的问题,有人知道问题出在哪里吗?

最佳答案

$stmt 仅在 mysqli_prepare 返回 false 时变为 bool 值。

发生这种情况时,意味着它无法准备查询,因此您需要检查错误:

$stmt = mysqli_stmt_init($db);
if (mysqli_stmt_prepare($stmt, 'INSERT INTO fragrances VALUES...')) {
//it's all good bind and execute here
}else{
//we have a problem
printf("Errormessage: %s\n", mysqli_error($db));
}

关于php mysql bind param 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26307176/

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