TypeError:在 Node js 中通过 SQL 查询提供时,参数回调必须是函数

Ray*_*d17 1 mysql node.js express

这是代码:

\n\n
 application.post(\'/Modification/SaveEdit/:idd\',function(req,res){\n var mem = req.body.memo;\n\n connection.query(\'UPDATE memos SET textMemo = ?\',mem,\'WHERE idMemo = ?\',req.params.idd, function (error, results, fields){\n        if (error) {\n    console.log("error ocurred",error);\n    res.send({\n      "code":400,\n      "failed":"erreur survenue"\n    })\n  }else{\n    console.log(\'Resultats: \', results);\n    res.send({\n      "code":200,\n      "success":"votre memo est bien modifi\xc3\xa9 ! "\n        });\n  }\n  });\n\n\n\n});\n
Run Code Online (Sandbox Code Playgroud)\n\n

我认为这是我的查询的语法,但我不知道如何正确编写它。

\n\n

这是错误:

\n\n
TypeError: argument callback must be a function when provided\nat Function.createQuery (/home/mohand/node_modules/mysql/lib/Connection.js:57:13)\nat Connection.query (/home/mohand/node_modules/mysql/lib/Connection.js:181:26)\nat /home/mohand/TpsWEB/DMajour/expreServer.js:146:13\nat Layer.handle [as handle_request] (/home/mohand/node_modules/express/lib/router/layer.js:95:5)\nat next (/home/mohand/node_modules/express/lib/router/route.js:137:13)\nat Route.dispatch (/home/mohand/node_modules/express/lib/router/route.js:112:3)\nat Layer.handle [as handle_request] (/home/mohand/node_modules/express/lib/router/layer.js:95:5)\nat /home/mohand/node_modules/express/lib/router/index.js:281:22\nat param (/home/mohand/node_modules/express/lib/router/index.js:354:14)\nat param (/home/mohand/node_modules/express/lib/router/index.js:365:14)\n
Run Code Online (Sandbox Code Playgroud)\n\n

提前致谢 !

\n

abo*_*doa 5

我怀疑您可能使用connection.query不正确。也许查看文档(https://github.com/mysqljs/mysql#performing-queries)。您为其提供 5 个参数,但它最多只能有 3 个。请尝试以下操作:

\n
application.post(\'/Modification/SaveEdit/:idd\',function(req,res){\n var mem = req.body.memo;\n\n connection.query(\'UPDATE memos SET textMemo = ? WHERE idMemo = ?\',[mem,req.params.idd], function (error, results, fields){\n        if (error) {\n            console.log("error ocurred",error);\n            res.send({\n                "code":400,\n                "failed":"erreur survenue"\n            })\n        }else{\n            console.log(\'Resultats: \', results);\n            res.send({\n                "code":200,\n                "success":"votre memo est bien modifi\xc3\xa9 ! "\n            });\n        }\n    });\n});\n
Run Code Online (Sandbox Code Playgroud)\n