const con = mysql.createConnection({
multipleStatements: true
});
mysql의 커넥션을 설정해주는 부분에서 multipleStatements를 true로 설정해준다.
이 부분에서는 MySQL을 처음 연동할때 host와 user 등 데이터베이스 정보등을 작성하는 곳이다.
const sql = 'select * from tv where title like ?;'+ 'select * from drama where title like ?;';
const params = [req.body.text];
db.con.query(sql,['%'+params+'%','%'+params+'%'],function(err, results){
if(err){
console.log(err);
reject(err);
}
resolve(results);
});
와일드카드를 사용하여 각각의 테이블에 입력된 유사한 값이 있는지 검사하는 쿼리문입니다.저런식으로 ; 세미클론을 각각의 쿼리문 뒤에 삽입해주고 +해주며 사용합니다.
참고자료 : https://github.com/mysqljs/mysql#multiple-statement-queries
GitHub - mysqljs/mysql: A pure node.js JavaScript Client implementing the MySQL protocol.
A pure node.js JavaScript Client implementing the MySQL protocol. - GitHub - mysqljs/mysql: A pure node.js JavaScript Client implementing the MySQL protocol.
github.com
'Programming > nodejs' 카테고리의 다른 글
[NodeJs] JWT(Json web Token) 로그인 Restful API 만들기 - 로그인편 (0) | 2022.01.17 |
---|---|
[NodeJs] JWT(Json web Token) 로그인 Restful API 만들기 - 회원가입편 (0) | 2022.01.16 |
[NodeJS] Express의 모든 정리 (0) | 2022.01.14 |
[NodeJS] 넷폴릭스 크롤링 (0) | 2021.10.03 |
[NodeJS] MySQL 연결오류 Client does not support authentication protocol requested by server; consider upgrading MySQL client (0) | 2021.09.03 |