Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么要获取val.slice不是一个函数_Javascript_Mysql_Express_Slice - Fatal编程技术网

Javascript 为什么要获取val.slice不是一个函数

Javascript 为什么要获取val.slice不是一个函数,javascript,mysql,express,slice,Javascript,Mysql,Express,Slice,我正在使用三层架构实现一个带有express的web应用程序。我将博客帖子作为资源存储在mysql数据库中。这是表格的外观: CREATE TABLE IF NOT EXISTS blogposts ( blogId INT NOT NULL AUTO_INCREMENT, title VARCHAR(255) NOT NULL, content VARCHAR(255) NOT NULL, posted VARCHAR(255) NOT NULL, im

我正在使用三层架构实现一个带有express的web应用程序。我将博客帖子作为资源存储在mysql数据库中。这是表格的外观:

CREATE TABLE IF NOT EXISTS blogposts (
    blogId INT NOT NULL AUTO_INCREMENT,
    title VARCHAR(255) NOT NULL,
    content VARCHAR(255) NOT NULL,
    posted VARCHAR(255) NOT NULL,
    imageFile VARCHAR(255) NOT NULL,
    userId INT NOT NULL,
    CONSTRAINT blog_id PRIMARY KEY (blogId),
    CONSTRAINT id_fk FOREIGN KEY (userId) REFERENCES accounts(personId)
);
现在,我想检索blogpost id sp,我向数据访问层中的数据库发送查询,并导出如下函数:

exports.getBlogpostId = function(blogId ,callback){

    const query = "SELECT * FROM blogposts WHERE blogId = ?"
    const value = [blogId]
    db.query(query, value, function(error, blogpost){
        if(error){
            callback("DatabaseError", null)
        }else{
            callback(null, blogpost)
        }
    })
}
然后我在我的业务逻辑层中使用它:

最后,我在表示层中使用它:

当我尝试检索id时,出现以下错误:

TypeError: val.slice is not a function
      at escapeString (/web-app/node_modules/sqlstring/lib/SqlString.js:202:23)
      at Object.escape (/web-app/node_modules/sqlstring/lib/SqlString.js:56:21)
      at Object.format (/web-app/node_modules/sqlstring/lib/SqlString.js:100:19)
      at Connection.format (/web-app/node_modules/mysql/lib/Connection.js:271:20)
      at Connection.query (/web-app/node_modules/mysql/lib/Connection.js:189:22)
      at Object.exports.getBlogpostId (/web-app/src/dal/blog-repository.js:19:8)
      at Object.exports.getBlogpostId (/web-app/src/bll/blog-manager.js:12:14)
      at /web-app/src/pl/routers/blogRouter/blogRouter.router.js:39:17
      at Layer.handle [as handle_request] (/web-app/node_modules/express/lib/router/layer.js:95:5)
      at next (/web-app/node_modules/express/lib/router/route.js:137:13)
我没有在任何地方调用slice方法,因此我不知道为什么会发生此错误

编辑: 发现这个问题时,我忘了在业务逻辑层中添加blogId作为参数


提前谢谢

查看错误该错误来自模块
sqlstring
,最本地的东西来自
/web app/src/pl/routers/blogrower/blogrower.router.js:39:17
,所以您必须在这里查看它

我在您包含的代码示例中没有看到片段?这是我在任何地方都没有使用它的东西…?@evolutionxboxwhat at at at at the the the the the the the the the the the the the the the the the the the it it it it it it it it it it it it it it it the the the the the the the the theline?blogManager.getBlogpostId(blogId,function(errors,blogpost))将调用业务逻辑层中的函数。将blogId从字符串转换为数字。现在,我忘记了在业务逻辑层函数中添加blogId作为参数。感谢您的回答。
router.get("/:blogId", function(request, response){

    const blogId = request.params.blogId
    blogManager.getBlogpostId(blogId, function(error, blogpost){

        const model = {
            error: error,
            blogpost: blogpost[0]
        }
        response.render("blogpost.hbs", model)
    })
})
TypeError: val.slice is not a function
      at escapeString (/web-app/node_modules/sqlstring/lib/SqlString.js:202:23)
      at Object.escape (/web-app/node_modules/sqlstring/lib/SqlString.js:56:21)
      at Object.format (/web-app/node_modules/sqlstring/lib/SqlString.js:100:19)
      at Connection.format (/web-app/node_modules/mysql/lib/Connection.js:271:20)
      at Connection.query (/web-app/node_modules/mysql/lib/Connection.js:189:22)
      at Object.exports.getBlogpostId (/web-app/src/dal/blog-repository.js:19:8)
      at Object.exports.getBlogpostId (/web-app/src/bll/blog-manager.js:12:14)
      at /web-app/src/pl/routers/blogRouter/blogRouter.router.js:39:17
      at Layer.handle [as handle_request] (/web-app/node_modules/express/lib/router/layer.js:95:5)
      at next (/web-app/node_modules/express/lib/router/route.js:137:13)