gpt4 book ai didi

javascript - 错误 : Incorrect arguments to mysqld_stmt_execute

转载 作者:行者123 更新时间:2023-12-05 02:02:57 27 4
gpt4 key购买 nike

我正在开发一个 nodeJs 项目,并为 mysql 数据库使用 npm 包 mysql2

我的 MySql 配置:-

let mysql = MYSQL.createConnection({
host: `${config.mysql.host}`,
user: `${config.mysql.user}`,
password: `${config.mysql.password}`,
database: `${config.mysql.db}`,
});

当我使用查询时

async function getUsers ({pageNumber}) { // suppose pageNumber = 1
const [result] = await mysql.execute(
`SELECT * FROM user LIMIT ?,20;`,
[pageNumber]
);
return result;
}

上面的代码运行良好。但是当我试图将任何数字与 pageNumber 相乘时,它会抛出错误 Error: Incorrect arguments to mysqld_stmt_execute

例如

async function getUsers ({pageNumber}) { // suppose pageNumber = 1
pageNumber = pageNumber * 20; // here we multiply 20 with pageNumber (20 is the row limit)
const [result] = await mysql.execute(
`SELECT * FROM user LIMIT ?,20;`,
[pageNumber]
);
return result;
}

上面的代码会抛出错误。

注意:- pageNumber 的类型是数字而不是字符串。

请帮忙。

最佳答案

这似乎是 MySQL 版本 8.0.22 中引入的错误,我从 8.0.19 更新后遇到同样的错误。不确定原因或适当的解决方案,在此期间我将值映射到字符串,按照 https://github.com/sidorares/node-mysql2/issues/1239#issuecomment-718471799 ,这似乎有效。

关于javascript - 错误 : Incorrect arguments to mysqld_stmt_execute,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65543753/

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