unfulat valueerror:mysqli_stmt :: execute():参数#1($ params)必须是列表数组
我正在尝试通过这两个查询在我的数据库中插入已准备好的多个值,这两个查询都出现故障,返回
未定的错误:致电未定义的方法mysqli_stmt :: bindvalue()
第一个代码或
undurew valueerror:mysqli_stmt :: execute():参数#1($ params) 必须是列表数组
第二个列表阵列。当我键入list
而不是array
时,它说
语法错误
注意所有变量,表和列名是一个简化的变体
我已经看到了很多类似的问题,但是它们都没有回答我的问题。 的“重复”。
甚至不是有人有解决方案
这是两个代码:
if(isset($_POST['ID'], $_POST['atr1'])){
$sql = $db -> prepare("INSERT INTO some_table (ID, atr_place) VALUES (':fir', ':sec')");
$sql -> bindValue(':fir', $_POST['ID'],);
$sql -> bindValue(':sec', $_POST['atr1'],);
$sql -> execute();
}
$sql = $db -> prepare("INSERT INTO some_table (ID, atr_place) VALUES (:fir, :sec)");
$sql -> execute(array(
':fir' => $_POST['ID'],
':sec' => $_POST['atr1'],
));
I'm trying to insert prepared statemant multiple values in my database through these two queries, which are both malfunctioning, returning either
Uncaught Error: Call to undefined method mysqli_stmt::bindValue()
for the first code or
Uncaught ValueError: mysqli_stmt::execute(): Argument #1 ($params)
must be a list array
for second one. When I type list
instead of array
, it says
syntax error
notice all variable, table and column names are a simplified variant
I've seen a lot of similar questions, but none of them answer my problem. Not even the one that this is the 'duplicate' of.
Does anyone have a solution, or, maybe, an alternative?
Here are the two codes:
if(isset($_POST['ID'], $_POST['atr1'])){
$sql = $db -> prepare("INSERT INTO some_table (ID, atr_place) VALUES (':fir', ':sec')");
$sql -> bindValue(':fir', $_POST['ID'],);
$sql -> bindValue(':sec', $_POST['atr1'],);
$sql -> execute();
}
$sql = $db -> prepare("INSERT INTO some_table (ID, atr_place) VALUES (:fir, :sec)");
$sql -> execute(array(
':fir' => $_POST['ID'],
':sec' => $_POST['atr1'],
));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于错误消息明确,您正在使用 mysqli 库与您的数据库进行通信。但是,您的代码似乎是基于使用 pdo 的示例完全是一个不同的库。尽管从表面上讲,某些函数名称相似,但实际上它们具有不同的API和要求。
例如,某些API差异是:
?
此代码应与MySQLI一起使用:
如果您有PHP 8.1或更高:
否则:
As the error messages make clear, you're using the mysqli library to communicate with your database. However your code seems to be based on examples which use PDO, which is a different library entirely. While superficially some of the function names are similar, they actually have different APIs and requirements.
For example, some API differences are:
?
This code should work with mysqli:
If you have PHP 8.1 or above:
Otherwise: