Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
6 views1 page

Cls DB Connection

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Cls DB Connection

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

const mysql = require('mysql2');

class clsDbConnection{
constructor() {
this.connection = null;
}

open() {
this.connection = mysql.CreateConnection({
host: 'your_host',
user: 'your_user',
password: 'your_password',
database: 'your_database_name',
});

this.connection.connect((error) => {
if(error) {
console.error('Connection error:', error.message);
} else {
console.log('Database connection opened');
}
});
}

close() {
if (this.connection) {
this.connection.end((error) => {
if(error) {
console.error('Disconnect error:', error.message);
} else {
console.log('Database connection closed');
}
});
} else {
console.log('No connection to close');
}
}
}

module.exports = clsDbConnection;

You might also like