var sql = 'UPDATE sensors SET time_sta=15,update_status=0,update_time=11 WHERE id="SCSQ210124001" AND num=1';
const [rows, fields] = await connection.execute(sql);
在云函数里 利用这二条指令 还操作MySQL 并且更新成功(自己云服务器上的)
但想把里面的值改为动态输入
先拟定id1,num1为用户输入
var id1 = "SCSQ210124001";
var num1 = 1;
var sql = 'UPDATE sensors SET time_sta=15,update_status=0,update_time=11 WHERE id=' + id1 + ' AND num='+num1 ;
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'num=1' at line 1"
结果报错
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'num=1' at line 1"
最后才发现要加空格
var sql = 'UPDATE sensors SET time_sta=11,update_status=1,update_time=11 WHERE id='+ id1 +' AND num='+num1 ;
这才更新进MySQL