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:
- ECMAScript arguments object
- Using ts-node to Execute .ts files Error [Solved]
- [Solved] Failed to execute ‘getRangeAt‘ on ‘Selection‘: 0 is not a valid index.“
- Failed to execute ‘setRequestHeader’ on ‘XMLHttpRequest’: String contains non ISO-8859-1 code point.
- The solution that needs alert to execute after using ajax
- [Solved] Uncaught DOMException: Failed to execute ‘readAsDataURL‘ on ‘FileReader‘: The object is already busy
- SVN Update Error: Please execute the ‘Cleanup‘ command.
- Vue Error: renren-fast-vue execute npm install Error [How to Solve]
- Vue2.0: How to Use vue3 api to encapsulate Axios
- JS to determine whether the string contains a character
- TypeScript error TS2345: Argument of type ‘String ‘is not assignable to parameter of type ‘string’
- request.js?b775:101 Uncaught (in promise) Error: Failed to convert value of type ‘java.lang.String’ to required type ‘java.lang.Long’;
- [Solved] Vue-router Error: Navigation cancelled from “/course“ to “/user“ with a new navigation.
- uniapp [Vue warn]: Error in onLoad hook: “TypeError: Attempting to change the setter of an unconfigu
- How to Use DOM to operate CSS
- @requestbody: How to Use or Not Use
- Vue3.0 error: Failed to resolve component el-form-item (el element to be unable to be displayed)
- How to React page to achieve entry and exit animation
- Vue: How to Solve error avoided redundant navigation to current location: “/xxx”
- Vue a page is mounted to send multiple requests at the same time, and the loading is processed uniformly