简体   繁体   English

使用mysql UPDATE插入换行符

[英]Insert Line break with mysql UPDATE

im using JSON.stringify and my stringified variable is: 即时通讯使用JSON.stringify和我的字符串化变量是:

{"ops":[{"insert":"drfsdfgg sdfg sdg \ns\ndfg\ndf\nsg\nsdfg\n"}]}

But when I do an UPDATE, the data is like that in mysql database: 但是当我执行UPDATE时,数据类似于mysql数据库中的数据:

 {"ops":[{"insert":"drfsdfgg sdfg sdg s dfg df sg sdfg "}]} 

I would like preserve all \\n like the INSERT! 我想像INSERT一样保留所有\\ n! ( yes INSERT WORKS ) (是INSERT WORKS)

the SQL query: SQL查询:

  connection.query("UPDATE products SET description ='" + req.body.description + "' WHERE id = " + req.body.id, function (error, results, fields) { if (!!error) { console.log('erreur'); } else { // console.log(results); res.json(); }; }); 

I found the solution, all is about the SQL syntax. 我找到了解决方案,所有内容都与SQL语法有关。 Thank you so much to me and my brain power. 非常感谢我和我的脑力。

  connection.query("UPDATE products SET description = ? WHERE id = " + req.body.id, [req.body.description], function (error, results, fields) { if (!!error) { console.log('erreur'); } else { // console.log(results); res.json(); }; }); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM