node 连接数据库异常

1 找不到mysql模块

报错:Cannot find module 'mysql'
处理:npm install mysql

2 建立了多次连接

报错:Cannot enqueue Handshake after already enqueuing a Handshake
处理:已经连接,不必多次连接。应当写成单例
 

3 node拼接sql语句异常   

报错:Unknown column 'xxx' in 'field list'
处理:var sql = `insert into user(user,password) values( '${result.username}', '${result.password}')`;
result.username是string类型依然要在外边加个单引号再插入''
外边不加单引号的时候:
insert into user(user,password) values(测试,1234asd)
加单引号:
insert into user(user,password) values(‘测试’,‘1234asd’)

猜你喜欢

转载自www.cnblogs.com/ltfxy/p/12360040.html