# Integrating with MYSQL

## Connection Setting

```javascript
// util/database.js
let mysql= require('mysql2');
let pool = mysql.createConnection({
	host: "localhost",
	user: "petercheng",
	password: "1234",
	database: "player"
});
module.exports = pool.promise();
```

## CRUD Operation

```javascript
const db = require("utils/database");

db.execute("SELECT * FROM products").then((res)=>{
   // ...
}).catch((err)=>{
   // ...
})


db.execute("INSERT INTO PRODUCTS (title , price) VALUES (?,?)", ["test", 123]).then((res)=>{
   // ...
}).catch((err)=>{
   // ...
})

```
