Complete the code to import the mysql2 package.
const mysql = require('[1]');
The mysql2 package is imported using require('mysql2').
Complete the code to create a connection using mysql2.
const connection = mysql.createConnection({ host: 'localhost', user: 'root', password: '[1]', database: 'testdb' });The password field should be the actual password string, e.g., 'password123'.
Fix the error in the code to connect to the database.
connection.[1](err => { if (err) throw err; console.log('Connected!'); });
The correct method to establish the connection is 'connect'.
Fill both blanks to query the database and handle the result.
connection.query('SELECT * FROM users WHERE id = ?', [[1]], (err, [2]) => { if (err) throw err; console.log(results); });
The first blank is the variable holding the user id to query. The second blank is the variable holding the query results.
Fill all three blanks to close the connection after the query.
connection.query('SELECT * FROM products', (err, results) => { if (err) throw err; console.log(results); connection.[1](() => { console.log('[2]'); process.[3](); }); });
Use connection.end() to close the connection, log 'Connection closed', then call process.exit() to end the program.
