When mysql2 is used to operate the database in express, the paging query will report an error error incorrect arguments to mysqld_stmt_execute
Question
Error reporting: error: incorrect arguments to mysqld_stmt_execute
// Query notes based on number of notes and number of pages
async getSomeNote(num, page) {
const fromNum = (page - 1) * num
const statement = `SELECT id,note_title,note_describe,note_createtime,note_sort FROM notes_test LIMIT ? ,? ;`
// There is a problem with the parameters fromNum, num passed in here, they are numeric at this point
const result = await connections.execute(statement, [fromNum, num])
console.log(result[0]);
return result[0]
}
reason
Statement is a query statement for operating the database and is of string type. The contents of the second parameter of execute will be inserted into the statement. At this time, the number type inserted should be of string type, so an error “wrong parameter” is reported.
Solution:
Change the passed in parameter to string type.
// Query notes based on number of notes and number of pages
async getSomeNote(num, page) {
const fromNum = (page - 1) * num
const statement = `SELECT id,note_title,note_describe,note_createtime,note_sort FROM notes_test LIMIT ? ,? ;`
// Direct string concatenation, converting number types to character types
const result = await connections.execute(statement, [fromNum+'', num+''])
console.log(result[0]);
return result[0]
}
Read More:
- JS async await Error: Uncaught SyntaxError: await is only valid in async functions and the top level bodies of modules
- [Solved] Vue-router Error: Navigation cancelled from “/course“ to “/user“ with a new navigation.
- uniapp Use render Function Error: [Vue warn]: Error in beforeCreate hook: “TypeError: Cannot read property ‘_i‘ of
- [Solved] UMI Project Error: uncaught at _callee3 at _calle3
- Error in created hook: “SyntaxError: Unexpected token u in JSON at position 0
- Vue2.0: How to Use vue3 api to encapsulate Axios
- JS to determine whether the string contains a character
- [Solved] SyntaxError: Cannot use import statement outside a module
- [Solved] NPM Error: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed
- Vant Applet: The Usage of Vant-dialog in Before-close
- @requestbody: How to Use or Not Use
- ECMAScript arguments object
- [Solved] Uncaught SyntaxError: Cannot use import statement outside a module
- [Solved] Invalid prop: type check failed for prop “modelValue“. Expected Number…
- How to use Runtime.getRuntime().Exec()
- Vue cannot read property ‘xxx’ of undefined solutions
- [Solved] Vue-vscode Error: Parsing error: Unexpected reserved word ‘await‘.
- Method to solve uncaught typeerror: cannot set property ‘onclick’ of null error
- JS to find the last character of the string and remove it
- Use of error attribute in element UI (solution of triggering only once)