2011-05-13 66 views
1

我使用expressjs和node-mysql模塊。我得到這個錯誤,當我發佈到更新動作expressjs mysql更新錯誤

/Users/mac/node_modules/mysql/lib/mysql/client.js:106 
     cb(err); 
     ^
TypeError: string is not a function 
    at String.CALL_NON_FUNCTION (native) 
    at Query.<anonymous> (/Users/mac/node_modules/mysql/lib/mysql/client.js:106:9) 
    at Query.emit (events.js:64:17) 
    at Query._handlePacket (/Users/mac/node_modules/mysql/lib/mysql/query.js:35:12) 
    at Client._handlePacket (/Users/mca/node_modules/mysql/lib/mysql/client.js:294:14) 
    at Parser.<anonymous> (/Users/mac/node_modules/mysql/lib/mysql/client.js:83:14) 
    at Parser.emit (events.js:64:17) 
    at /Users/mac/node_modules/mysql/lib/mysql/parser.js:75:14 
    at Parser.write (/Users/mac/node_modules/mysql/lib/mysql/parser.js:580:7) 
    at Socket.<anonymous> (/Users/mca/node_modules/mysql/lib/mysql/client.js:63:16) 

我用這個動作:

app.post('/post/:id/edit', function(req, res){ 
     var id = req.params.id; 
     var query = client.query(
      'UPDATE '+POST, 
      'SET title = ?, text = ?', 
      [req.body.title, req.body.text ], 
     ' WHERE id='+id 
     ); 
     res.redirect('/'); 
    }); 

有什麼不對?

+0

哪裏定義了'cb'? – jcolebrand 2011-05-13 16:36:29

回答

2
var query = client.query(
     'UPDATE '+POST + 
     ' SET title = ?, text = ?' + 
     ' WHERE id='+id, 
     [req.body.title, req.body.text ] 
    ); 

您使用的,代替+

你想連接你所有的字符串部分,然後在最後通過你的參數數組。

+0

是的,謝謝。在SET之前需要一個空格,並且工作正常。 'SET title =?,text =?' – vegas 2011-05-13 16:49:10

+0

@vegas,而我在它。刪除mysql,使用沙發或mongo – Raynos 2011-05-13 17:03:57

+0

下一步 - > nosql :) – vegas 2011-05-13 17:08:52